perf: remove indirection from ElementAwareArrayList#2333
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Replaces the internal ArrayList<Entry> backing of ElementAwareArrayList with a manually managed Entry[] array to remove a layer of indirection, reducing per-call overhead in this hot data structure. Adds explicit resize, truncateTo, and clear/innerClear helpers, and factors add(int, T) into addWithoutGaps/addWithGaps paths.
Changes:
- Switched backing storage from
ArrayList<Entry>to a manually grown@Nullable Entry[]withDEFAULT_CAPACITY = 16and doubling growth. - Introduced
resize,truncateTo, andinnerClearhelpers; added a publicclear()override; refactoredadd(int, T)into helper methods. - Updated all internal accesses (
addEntry,partialCompact,remove,forEach*, list iterator) to operate directly on the array.
|
Collaborator
Author
Christopher-Chianelli
approved these changes
Jun 4, 2026
| @SuppressWarnings("unchecked") | ||
| private void resize(int minCapacity) { | ||
| if (entries == null) { | ||
| entries = (Entry[]) Array.newInstance(Entry.class, Math.max(DEFAULT_CAPACITY, minCapacity)); |
Contributor
There was a problem hiding this comment.
Why not entries = new Entry[Math.max(DEFAULT_CAPACITY, minCapacity)]? Entry is not generic, given you can do Entry.class?
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.




Only a small optimization, but generally helpful.