Optimizes IonValue.getType() to avoid vtable/itable lookups when invoked on IonStruct values. #928
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.
Description of changes:
Also adds a 'jmh' target that allows us to add microbenchmarks for targeted performance testing. These benchmarks are run using
./gradlew jmh
. Example output:This is optional and can be removed from this PR if reviewers have objections. I think it's nice because it reduces the effort required to add new JMH benchmarks that are more targeted than the
ion-java-benchmark-cli
. Note that we followed this same pattern in ion-java-path-extraction. New benchmarks need not even be committed, but having the JMH framework committed allows for quick local experimentation. I'm proposing to commit the new IonValueGetTypeBenchmark mostly as an example.As for the proposed change, the existing implementation of
IonValue.getType()
is an interface method with 14 implementations, requiring an itable lookup to invoke. This has been shown to be much slower than invoking afinal
method or an abstract method with two or fewer implementations. The proposed change adds a special case forIonStructLite.getType
that avoids itable/vtable lookups. All other types fall back to the existing implementations, now calledgetTypeSlow()
.IonStructLite is chosen for the fast path because it is the most commonly used container type as well as one of the most common of all types. This is important because internal usages of IonValue.getType() occur on container values much more often than on scalars. Although the added microbenchmarks show this change is performance-neutral, performance testing within a large application that heavily uses Ion structs demonstrates significant benefit.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.