Reduce allocations when building ClassNameTries#86
Merged
Conversation
Instead of allocating a BitSet on every put, each builder now has its own re-usable cache to record the jump indexes to update after we know how much content was added to the trie.
There was a problem hiding this comment.
Pull request overview
This PR optimizes ClassNameTrie.Builder to reduce per-put() allocations by replacing the per-insertion BitSet with a reusable, builder-scoped int[] cache of jump indices that need offset updates after insertion size is known. This aligns with the builder’s expanded usage at runtime, where allocation pressure matters more.
Changes:
- Removed
BitSetallocation ininsertMappingand replaced it with a reusablejumpIndexes+jumpIndexCountcache. - Added
recordJumpIndex(int)helper to grow and populate the cached jump-index list. - Simplified
longJumpsgrowth logic usingArrays.copyOf(...).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
amarziali
approved these changes
May 28, 2026
|
Nice optimization ! |
bric3
approved these changes
May 28, 2026
dougqh
approved these changes
May 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What Does This Do
Instead of allocating a BitSet on every put, each builder now has its own re-usable cache to record the jump indexes to update after we know how much content was added to the trie.
Motivation
Originally the builder was only used to create tries at build-time- since then its use has widened to include building tries at runtime. This optimization reduces allocations for that particular use-case.
Contributor Checklist
Jira ticket: [PROJ-IDENT]