Here's a quick steps to get your Groovy classes optimised using Soot framework.
Problems
When using Groovy, sometime we encounter the OutOfMemoryException because PermGen space ran out. Optimisation of class files could help saving memory usage of JVM.
Soot Framework
Soot Framework is a bytecode optimisation, and manipulation framework, developed at McGill University, for Java. It comes with a vast set of optimisation techniques. We can also develop our own optimisation using the framework provided.
Quick Optimisation
With Soot, you can just run
to obtain a optimised class.
Analysis
A trivial class is used in this analysis. The class is illustrated in Jimple format, an intermediate representation supported by Soot to see what's done with Soot optimisation.
Here's a command to get a Jimple file:
and the following is a command for applying optimisation:
We've now got two Jimple files, and can use a text editor to compare them. You can get this two files from the attachment below to see their differences.
The result from the optmisation shows that Soot can reduce the file size by 8.5%. This number is expected to be large when we apply the optimisation to the whole program.