You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by Jennifer Strater <je...@gmail.com> on 2017/04/06 09:12:57 UTC

Potential Bytecode Optimization

Hi all,

As part of a special course on compilers, I've been looking at the groovy
compiler to see how it works.  One thing we noticed is that the bytecode
generated by the Groovy compiler contains several instances of loading a
value onto the stack immediately followed by a pop. I understand how it
happens and finding a way to prevent it would be very difficult.
Therefore, I've been looking at a post pass optimization to remove these
unnecessary operations.

I can remove the extra instructions, but I'd like to see if it makes a
difference. I've used small scripts from the benchmark folder in the groovy
source repository and I've run a benchmark against the application itself,
but there hasn't been a significant difference.  Is there a better way to
approach this?

Thanks,
Jenn

Re: Potential Bytecode Optimization

Posted by Jochen Theodorou <bl...@gmx.org>.

On 06.04.2017 11:12, Jennifer Strater wrote:
[...]
> I can remove the extra instructions, but I'd like to see if it makes a
> difference.

The JVM is very good at removing dead code. The removal of dead code 
even lowers the actual code size considered for inlining. So I don't 
think I can give an example in which I am sure it will matter for 
performance. It will probably matter on startup during class validation 
and verification


bye Jochen

Re: Potential Bytecode Optimization

Posted by Cédric Champeau <ce...@gmail.com>.
Hi Jenn!

I think a good way to test this is to use JMH. And for this particular
scenario, find a method that would exceed the maximum bytecode size for
inlining, and would go below that limit with your optimization.

2017-04-06 11:12 GMT+02:00 Jennifer Strater <je...@gmail.com>:

> Hi all,
>
> As part of a special course on compilers, I've been looking at the groovy
> compiler to see how it works.  One thing we noticed is that the bytecode
> generated by the Groovy compiler contains several instances of loading a
> value onto the stack immediately followed by a pop. I understand how it
> happens and finding a way to prevent it would be very difficult.
> Therefore, I've been looking at a post pass optimization to remove these
> unnecessary operations.
>
> I can remove the extra instructions, but I'd like to see if it makes a
> difference. I've used small scripts from the benchmark folder in the groovy
> source repository and I've run a benchmark against the application itself,
> but there hasn't been a significant difference.  Is there a better way to
> approach this?
>
> Thanks,
> Jenn
>