Add negative-caching in PreferredConstructor.isConstructorParameter(…).
We now cache the negative outcome of PreferredConstructor.isConstructorParameter(…) to avoid iterations and iterator allocations which roughly improves typical converter usage by roughly 32%. Before: Benchmark Mode Cnt Score Error Units TypicalEntityReaderBenchmark.simpleEntityGeneratedConstructorAndField thrpt 10 6848447,474 ± 554354,377 ops/s After Benchmark Mode Cnt Score Error Units TypicalEntityReaderBenchmark.simpleEntityGeneratedConstructorAndField thrpt 10 9071099,879 ± 1423166,087 ops/s Closes #2295.
This commit is contained in:
@@ -115,6 +115,10 @@ public class PreferredConstructor<T, P extends PersistentProperty<P>> {
|
||||
/**
|
||||
* Returns whether the given {@link PersistentProperty} is referenced in a constructor argument of the
|
||||
* {@link PersistentEntity} backing this {@link PreferredConstructor}.
|
||||
* <p>
|
||||
* Results of this call are cached and reused on the next invocation. Calling this method for a
|
||||
* {@link PersistentProperty} that was not yet added to its owning {@link PersistentEntity} will capture that state
|
||||
* and return the same result after adding {@link PersistentProperty} to its entity.
|
||||
*
|
||||
* @param property must not be {@literal null}.
|
||||
* @return {@literal true} if the {@link PersistentProperty} is used in the constructor.
|
||||
@@ -132,12 +136,13 @@ public class PreferredConstructor<T, P extends PersistentProperty<P>> {
|
||||
boolean result = false;
|
||||
for (Parameter<?, P> parameter : parameters) {
|
||||
if (parameter.maps(property)) {
|
||||
isPropertyParameterCache.put(property, true);
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
isPropertyParameterCache.put(property, result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user