Skip to content

[Java] Make IntArrayList honour agrona.disable.bounds.checks - #394

Closed
arvidjonasson wants to merge 1 commit into
aeron-io:masterfrom
arvidjonasson:Add-agrona.disable.bounds.checks-to-IntArrayList
Closed

arvidjonasson wants to merge 1 commit into
aeron-io:masterfrom
arvidjonasson:Add-agrona.disable.bounds.checks-to-IntArrayList

Conversation

@arvidjonasson

Copy link
Copy Markdown
Contributor

This is a breaking change. Makes IntArrayList (and LongArrayList) skip bounds checking when agrona.disable.bounds.checks is set to true, which is the same parameter as in DirectBuffer. Bounds checking is not completely gone because there is still the implicit 0 <= index < elements.length bounds check inserted by the JVM when indexing arrays, but it reduces the the number of bounds checks from 2 to 1 (the C2 JIT was never smart enough to deduplicate the bounds checks).

@vyazelenko

Copy link
Copy Markdown
Contributor

agrona.disable.bounds.checks is a setting for DirectBuffer and has nothing to do with collections. Explicit index checks is what JDK collections have as well. Those additional branches should be well predicted by the CPU and cost virtually nothing.

@vyazelenko vyazelenko closed this Nov 8, 2026
@arvidjonasson

arvidjonasson commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor Author

In my testing, removing the bounds checking made getInt between 30% to 59% faster (depending on the array size) even when the function had only ever taken one branch. Would you consider adding a property to remove bounds checking for IntArrayList?

@vyazelenko

Copy link
Copy Markdown
Contributor

@arvidjonasson Can you provide a benchmark that demonstrates the huge performance cost of the index checking?

P.S. I've pushed a change (9b5c189) where the custom index was replaced with java.util.Objects.checkIndex(int, int) call. This is what java.util.AbstractList and friends are using.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants