Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
1.0-beta-4
-
None
Description
I have done a bit of profiling on groovy compiler and it turned out that for simple test (10 times compiling 4kb groovy script), 75% of time was spent in CompileUnit.loadClass. It is trivial to cache results of this calls. With attached patch, time for running test was reduced from 6500ms to 1800ms - almost 4x speedup for this single method. Cost is rather small - map with type->class (and most important NO_CLASS) cache.
After removing this hotspot, another loadClass hotspots have appeared - it would be best to search for everything which has loadClass in name and refactor/cache everything which is not really needed or can be done in different way. Loadclass call is extremly heavy - it should be avoided at all costs, even if this means having cache of answers at many levels.
Another problem is control-flow through exceptions, which is enforced through ClassLoader.loadClass. With cache, it could be possibly avoided - exceptions are also quite heavy, especially if they are thrown always for common case of non-class identifier. But this is major change, not for this patch.