rdf-canonize
rdf-canonize copied to clipboard
Optimize IdentifierIssuer existing Map.
- Change clones from always-copy to copy-on-write.
- Depending on shape of data, this can reduce
Map
copies by ~90%. However, in some data patterns, these will have very few entries, so overall performance may not be noticeably effected.
This patch may need more work. It doesn't seem to hurt anything. Benchmarking was difficult, and it may even be slightly slower for small tests? Unclear why that would be other than faulty benchmarking.
I had expected this to show up better in benchmarks. But it seems the timing effect may be minimal. Perhaps the memory usage of fewer maps is more measurable, but I'm unsure how best to do so. For example, running the test suite with just the async code, the clone
calls will do 25602 Map copies. With this patch it will only do 2307 copies.
As noted in the code, there is a case of clones being done, but they won't unref the shared map, so another user of that map might copy it needlessly. This is a bit more involved to fix, and it's unclear how often that may happen.