Your understanding of how varargs calls are made is correct - it's nothing
more than sugar for an allocated array to store the args.  Your bench,
however, explicitly disables inlining of the varargs method, and thus
prevents escape analysis from potentially eliminating the array
allocation.  Try the bench without disabling inlining and I would hope the
JIT is able to remove the allocation and scalarize instead.

On Mon, Apr 30, 2018 at 12:39 PM, Ionut Balosin <ionut.balo...@gmail.com>
wrote:

> 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
>
> --
> You received this message because you are subscribed to the Google Groups
> "mechanical-sympathy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mechanical-sympathy+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"mechanical-sympathy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mechanical-sympathy+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to