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

Share "reflection based ClassNodes" that wrap the same java.lang.Class

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 1.7-beta-1
    • None
    • None

    Description

      ResolveVisitor will look for classes on the classpath by calling ClassLoader.loadClass(). For performance, it maintains a cache of the resulting Classes. Each class is then wrapped in a ClassNode. We could cache the ClassNodes instead, and have only a single ClassNode for each java.lang.Class. Should have no functional change and should reduce memory during compilation a little.

      On Jan. 31, 2009, Jochen Theodorou said on the dev mailing list:

      class A<T>{}

      def foo = new A<Integer>

      We have a ClassNode for A<T>, which is different then A<Integer>, which redirects to A<T>. So what is surplus here? The A<T> node, but not the A<Integer> node, which is far more lightweight anyway. Also instead of using setType you have to set a redirect then of course.

      Will it make a significant change to the performance... much less than you may expect I think. The thing that really costs is getting all the methods and fields for the class. So unless we do that, no harm will be done. Atm we need this information only if an interface is implemented or a class is extended. In other cases the information is not needed and not get.

      So if we have multiple classes extending other classes with a long set of parent classes, then it might get us a bit performance. So I see a use. But for the test case build itself you most probably won't see much of a performance increment.

      Which doesn't mean you shouldn't check that out... creating much more ClassNodes than needed is also a memory thing, and since the compiler ssems to use more memory than in the past it is nice to reduce that again a little, even if it is only for a bit.

      Attachments

        Activity

          People

            mcspanky Martin C. Martin
            mcspanky Martin C. Martin
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: