Lambda vs Manual Metafactory
posted 1 year ago
I was toying around with creating lambdas using LambdaMetafactory, and I wondered if there was any speed difference between reflectively calling a method, calling a MethodHandle, a manually created lambda, and a regular old lambda. For simplicity, the function to be tested is a plain static void method with no parameters. I let the tests go for about 12000 dummy runs to hopefully warm up the JVM into compiling the bytecode before timing them, 10000 invocations at a time. Interestingly, most of the time, invoking the regular old lambda, and even the reflective Method, was a little faster than calling the lambda created using LambdaMetafactory and the MethodHandle. Why is this?
Also, I don't have the code on me right now, but I will put it here when I can.