Here's a quick steps to get your Groovy classes optimised using Soot framework.
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 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.
With Soot, you can just run
to obtain a optimised class.
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.
This is an updated result when applying the more complex optimisation to two of Groovy packages, groovy.lang and groovy.xml.
Please note that not all Groovy classes were used in this experiment. Just two mentioned packages resides in the "groovy-1.1" folder. This experiment has done by performing optimisation package that requires Static Single Assignment (SSA) representation of Java classes. Soot supports this through Shimple format. The "-via-shimple" option shown in the command line is to enable this kind of optimisation. The result is better than using only Jimple optimsation. Size of Groovy classes in the two packages is reduced by 16.34%.