Repository navigation
Avoid allocations when comparing componentized DotNames - #738
Merged
Merged
Conversation
Member
|
I wouldn't expect this to be faster than my version, but measures trump expectations any day (and night). The benchmark is good, let me rerun it locally just to confirm. |
Ladicek
marked this pull request as ready for review
November 9, 2026 14:57
Ladicek
reviewed
Nov 9, 2026
DotName.compareTo() for two componentized names used to flatten both names into freshly allocated arrays of components before walking them in parallel. This is a hot path: the indexer sorts the annotations of every class, method and field by name, and frameworks then look up annotations by binary search over those sorted arrays, calling compareTo() several times per lookup. Two array allocations plus two prefix-chain walks per comparison add up to a lot of garbage on a large index. Make the general case allocation-free. Instead of flattening into arrays, compute the depth of each name once and fetch the component at a given index by walking the (short) prefix chain on demand. The character-by-character comparison algorithm is unchanged, only the way components are obtained differs. The `null` sentinel that terminated the flattened arrays is now returned by componentAt() when the index is past the last component. Also add a JMH benchmark simulating the typical framework pattern: look up a couple dozen well-known annotation names, created with DotName.createSimple() as framework constants usually are, as well as componentized ones, on a method carrying a few indexer-created annotations, and sort indexer-created annotations as the indexer does. Co-Authored-By: Ladislav Thon <[email protected]>
Member
|
OK, here are my results:
I didn't measure allocations, but this is a clear improvement. Good work, thank you! |
Ladicek
approved these changes
Nov 9, 2026
Contributor
Author
|
Let's be honest: the implementation was mostly Claude :). But it did take some work to identify all these areas of improvements and see which were promising enough. |
Member
|
I'll release right away. |
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.
This was detected when benchmarking the Quarkus test suite for the Hibernate ORM extension. An inefficiency in the HV extension code path was making this a hotpath.
While I will work on addressing the HV issue. I thought it was worth reporting this issue here as it could affect other extensions.
Knowing you, you will probably come up with a completely different implementation :). But at least you have a benchmark and an idea of the problem :).
Full test suite passes.
DotName.compareTo() for two componentized names used to flatten both names into freshly allocated arrays of components before walking them in parallel. This is a hot path: the indexer sorts the annotations of every class, method and field by name, and frameworks then look up annotations by binary search over those sorted arrays, calling compareTo() several times per lookup. Two array allocations plus two prefix-chain walks per comparison add up to a lot of garbage on a large index.
Make the general case allocation-free. Instead of flattening into arrays, compute the depth of each name once and fetch the component at a given index by walking the (short) prefix chain on demand. The character-by-character comparison algorithm is unchanged, only the way components are obtained differs. The
nullsentinel that terminated the flattened arrays is now returned by componentAt() when the index is past the last component.Results of the benchmark:
The reduction of allocations is what I was after. CPU seems to be relatively fine. Machine was mostly idle but not fully.