You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Java] Make IntArrayList honour agrona.disable.bounds.checks - #394
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).
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.
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?
@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.
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
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.
This is a breaking change. Makes
IntArrayList(andLongArrayList) skip bounds checking when agrona.disable.bounds.checks is set to true, which is the same parameter as inDirectBuffer. Bounds checking is not completely gone because there is still the implicit 0 <=index<elements.lengthbounds 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).