Potential Bytecode Optimization

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Potential Bytecode Optimization

Jennifer Strater
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Potential Bytecode Optimization

Cédric Champeau
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 <[hidden email]>:
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

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Potential Bytecode Optimization

Jochen Theodorou
In reply to this post by Jennifer Strater


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
Loading...