Protect against HashMap rehash spikes in UnresolvedSamples #737
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While adding support for in-kernel unwinding with sample rates as high as 4KHz, sample dropping became an issue. Looking closer using a
perf recordof compiler running on 16 CPU, 4KHz samples, rehashing was taking over 260ms in the worst case (see "Stack Chart" and highlighting rehash): https://share.firefox.dev/3Y32wsTThis changes so that UnresolvedStacks uses a BTreeMap for the interning storage, which has a much more bounded O(log n) worst case insertion. An LRU hash map serves on top as an O(1) fast path.
The new implementation is roughly on par and perhaps slightly faster, and processing time spikes are almost gone:
https://share.firefox.dev/4pMM9wy
Footnote, the
stacksarray itself also suffers from O(n) realloc behavior, but that doesn't seem to be problematic yet, so I'll leave this for when it's found to be a problem in the future.