Skip to content

Conversation

@bbakerman
Copy link
Member

@bbakerman bbakerman commented Oct 13, 2022

Another PR on improving getter access. Thanks to @arlampin for the inspiration.

https://wttech.blog/blog/2020/method-handles-and-lambda-metafactory/
https://www.optaplanner.org/blog/2018/01/09/JavaReflectionButMuchFaster.html

Early benchmarks on direct access versus lambda access versus the reflection method access we have today

Benchmark                                       Mode  Cnt         Score         Error  Units
GetterAccessBenchmark.measureDirectAccess      thrpt   15  81199548.105 ± 2717206.756  ops/s 0% slower (baseline)
GetterAccessBenchmark.measureLambdaAccess      thrpt   15  79622345.446 ± 1183553.379  ops/s 2% slower
GetterAccessBenchmark.measureReflectionAccess  thrpt   15  46102664.133 ± 4091595.318  ops/s 50% slower

JDK 1.8.0_191, Java HotSpot(TM) 64-Bit Server VM, 25.191-b12 - Mac M1

Another PR on improving getter access
@andimarek
Copy link
Member

@bbakerman I think is worth to also benchmark on JDK 17.

Fixed test where parameters are present
Benchmark fix up
@bbakerman bbakerman changed the title WIP LambdaMetafactory support for property fetches LambdaMetafactory support for property fetches Oct 14, 2022
@bbakerman
Copy link
Member Author

JDK 17


Benchmark                                       Mode  Cnt          Score          Error  Units
GetterAccessBenchmark.measureDirectAccess      thrpt   15  458411420.717 ± 34329506.990  ops/s 0%
GetterAccessBenchmark.measureLambdaAccess      thrpt   15  334158880.091 ± 10666070.698  ops/s 27% slower
GetterAccessBenchmark.measureReflectionAccess  thrpt   15   63181868.566 ±  3887367.970  ops/s  86% slower

}

private static class CachedFunction {
Function<Object, Object> getter;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember reading that declaring fields final might improve method reference performance so it might apply here. Although maybe it was just static final constants.

@dondonz dondonz added this to the 20.0 milestone Oct 29, 2022
Function<Object, Object> getterFunction = mkCallFunction(sourceClass, candidateMethod.getName(), candidateMethod.getReturnType());
return Optional.of(getterFunction);
} catch (Throwable ignore) {
// if we can make a dynamic lambda here, then we give up and let the old property fetching code do its thing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// if we can make a dynamic lambda here, then we give up and let the old property fetching code do its thing
// if we can't make a dynamic lambda here, then we give up and let the old property fetching code do its thing

@bbakerman bbakerman merged commit 9787497 into master Oct 31, 2022
@dondonz dondonz deleted the LambdaMetafactory_investigation branch November 11, 2022 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants