Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize IdentifierIssuer existing Map. #65

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

davidlehn
Copy link
Member

  • 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.

- 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.
@davidlehn davidlehn force-pushed the copy-on-write-identifier-map branch from 80e1b96 to 3d15697 Compare March 31, 2023 00:34
@codecov-commenter
Copy link

codecov-commenter commented Mar 31, 2023

Codecov Report

Merging #65 (1e25326) into main (19f5f8c) will increase coverage by 0.07%.
The diff coverage is 100.00%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##             main      #65      +/-   ##
==========================================
+ Coverage   88.44%   88.52%   +0.07%     
==========================================
  Files          10       10              
  Lines         580      584       +4     
==========================================
+ Hits          513      517       +4     
  Misses         67       67              
Impacted Files Coverage Δ
lib/IdentifierIssuer.js 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Member

@dlongley dlongley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems ok ... the TODO should be moved to an issue. By removing the prefix _ from _existing it will move it into public space which seems like a bad idea. Let's keep it. It's ok that it's used in "protected" space by the same class.

this.prefix = prefix;
this._existing = existing;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep the prefixed _ so only protected / internal usage of this is expected.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. But it's not consistent. counter is only used internally, but has no leading _.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants