Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
1.8-beta-1
-
None
-
None
-
Patch
Description
We use Groovy to process a large data object. Profiling shows an extraordinary number of strings were allocated due to the use of closure. This is because MetaClassImpl tries to determine if a property has a catagory setter or getter by trial and error:
String getterName = "get" + MetaClassHelper.capitalize(name);
MetaMethod categoryMethod = getCategoryMethodGetter(sender, getterName, false);
And this is done for every get/set property. This is bad if the number of objects/properties is large.
As GroovyCategorySupport actually already caches all the category methods, we can add additional cache maps from a property name to its getter or setter method name if the category method is a candidate for a getter or setter. In this way, no more on-the-fly concatenation of getter name or setter name. BTW, I did not add any cleanup for the property getter/setter maps. They would be removed when the outer endScope removes the ThreadCategoryInfo.
This code would add a very small overhead to apply use category, but pays off when a large number of properties are involved.BY