Skip to content

perf: remove indirection from ElementAwareArrayList#2333

Merged
triceo merged 1 commit into
TimefoldAI:mainfrom
triceo:eaal
Jun 4, 2026
Merged

perf: remove indirection from ElementAwareArrayList#2333
triceo merged 1 commit into
TimefoldAI:mainfrom
triceo:eaal

Conversation

@triceo

@triceo triceo commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator

Only a small optimization, but generally helpful.

Copilot AI review requested due to automatic review settings June 2, 2026 11:31
@triceo triceo self-assigned this Jun 2, 2026
@triceo triceo added this to the v2.2.0 milestone Jun 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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[] with DEFAULT_CAPACITY = 16 and doubling growth.
  • Introduced resize, truncateTo, and innerClear helpers; added a public clear() override; refactored add(int, T) into helper methods.
  • Updated all internal accesses (addEntry, partialCompact, remove, forEach*, list iterator) to operate directly on the array.

@sonarqubecloud

sonarqubecloud Bot commented Jun 2, 2026

Copy link
Copy Markdown

@triceo

triceo commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator Author

Ping @Christopher-Chianelli

@Christopher-Chianelli Christopher-Chianelli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@SuppressWarnings("unchecked")
private void resize(int minCapacity) {
if (entries == null) {
entries = (Entry[]) Array.newInstance(Entry.class, Math.max(DEFAULT_CAPACITY, minCapacity));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not entries = new Entry[Math.max(DEFAULT_CAPACITY, minCapacity)]? Entry is not generic, given you can do Entry.class?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

image

@triceo triceo merged commit e52f30f into TimefoldAI:main Jun 4, 2026
18 of 19 checks passed
@triceo triceo deleted the eaal branch June 4, 2026 17:59
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.

3 participants