Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-4351

Improve Category Performance and Memory

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.8-beta-1
    • 1.7.5, 1.8-beta-2
    • 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

      Attachments

        1. main.patch
          6 kB
          Re Lai
        2. CategoryTest.groovy
          0.6 kB
          Re Lai
        3. CategoryTest_benchmark.groovy
          0.7 kB
          Re Lai

        Activity

          People

            guillaume Guillaume Sauthier
            relai Re Lai
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: