Skip to content

Conversation

@ishitatsuyuki
Copy link
Contributor

While adding support for in-kernel unwinding with sample rates as high as 4KHz, sample dropping became an issue. Looking closer using a perf record of 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/3Y32wsT

This 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 stacks array 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.

While adding support for in-kernel unwinding with sample rates as high
as 4KHz, sample dropping became an issue. Looking closer using a
`perf record` of 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/3Y32wsT

This 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 `stacks` array 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.
Copy link
Owner

@mstange mstange left a comment

Choose a reason for hiding this comment

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

Nice, thanks!

@mstange mstange merged commit 80bbe09 into mstange:main Dec 22, 2025
15 checks passed
@ishitatsuyuki ishitatsuyuki deleted the rehash-spikes branch December 22, 2025 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants