neoremind commented on issue #1875: [CALCITE-3873] Use global caching for ReflectiveVisitDispatcher implementation URL: https://github.com/apache/calcite/pull/1875#issuecomment-605405488 @vlsi I refined the benchmark in [my branch](https://github.com/neoremind/calcite/blob/refvisit_benchmark/ubenchmark/src/jmh/java/org/apache/calcite/benchmarks/ReflectiveVisitDispatcherTest.java). The result is as below. ``` Benchmark Mode Cnt Score Error Units ReflectiveVisitDispatcherTest.testGlobalCaching avgt 3 137.270 ± 32.275 ns/op ReflectiveVisitDispatcherTest.testInstanceCachingWithLambdaFactory avgt 3 92459.660 ± 56777.698 ns/op ReflectiveVisitDispatcherTest.testInstanceCachingWithLambdaFactoryThreadLocalInitialize avgt 3 199.687 ± 24.755 ns/op ReflectiveVisitDispatcherTest.testInstanceCachingWithMethodHandle avgt 3 2421.131 ± 633.756 ns/op ReflectiveVisitDispatcherTest.testInstanceCachingWithMethodHandleThreadLocalInitialize avgt 3 218.616 ± 41.754 ns/op ReflectiveVisitDispatcherTest.testInstanceCachingWithReflection avgt 3 224.603 ± 22.770 ns/op ReflectiveVisitDispatcherTest.testInstanceCachingWithReflectionThreadLocalInitialize avgt 3 218.406 ± 9.620 ns/op ``` From the result, it seems the pre-work is time consuming for both `MethodHandle` and `LambdaFactory` (built upon MethodHandle). To eliminate the initialization effect, I try to use ThreadLocal to initialize once, the result do verifies that, in terms of time cost, LambdaFactory < MethodHandle = reflection, but the gap is very small. Overall, back to what the PR brings, the global caching stragety with reflection invocation can satisfy our requirement during the whole process, instead of caching per instance or per thread.
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services