Skip to content

Reduce allocations when building ClassNameTries#86

Merged
mcculls merged 1 commit into
mainfrom
mcculls/reduce-trie-builder-alloc
Jun 1, 2026
Merged

Reduce allocations when building ClassNameTries#86
mcculls merged 1 commit into
mainfrom
mcculls/reduce-trie-builder-alloc

Conversation

@mcculls
Copy link
Copy Markdown
Collaborator

@mcculls mcculls commented May 23, 2026

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]

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.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 BitSet allocation in insertMapping and replaced it with a reusable jumpIndexes + jumpIndexCount cache.
  • Added recordJumpIndex(int) helper to grow and populate the cached jump-index list.
  • Simplified longJumps growth logic using Arrays.copyOf(...).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@bric3
Copy link
Copy Markdown

bric3 commented May 28, 2026

Nice optimization !

@mcculls mcculls merged commit 8b08055 into main Jun 1, 2026
9 checks passed
@mcculls mcculls deleted the mcculls/reduce-trie-builder-alloc branch June 1, 2026 10:10
@github-actions github-actions Bot added this to the 0.1.0 milestone Jun 1, 2026
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.

5 participants