Hello All,
I am currently investigating the performance and how works in case of calling a method with explicit parameters vs. a varargs method. Please find attached the JMH Bench and ASM files generated after running the JMH test. (I did not inline them since are quite long)
I would like double check with you if my understanding is correct (btw I am not an ASM expert), especially in regards to native code generated for varargs method, which basically explains the difference in performance between these two.
In such case, to me it seems before calling the varargs method ( e.g. private int var_args(int... args) ) an array is allocated, parameters are collected from stack (i.e. mov r11d,DWORD PTR [rbp+0x18]), copied into that array and then var_args method itself is called (i.e. call 0x00007f8764dcf640)
-- array allocation and stack parameter manipulation might be an explanation for difference in elapsed time
Benchmark (param1) (param2) (param3) (param4) Mode Cnt Score Error Units
MethodParametersJmh.explicit_4_params_bench 3 5 7 9 avgt 15 5.464 ± 0.112 ns/op
MethodParametersJmh.var_args_4_params_bench 3 5 7 9 avgt 15 8.520 ± 0.127 ns/op
Could you please comment / invalidate my understanding?
Please find attached Java source file and JMH test results + ASM.
Thanks
Ionut