Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8189747

JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.

    Details

    • Type: Bug
    • Status: Open
    • Priority: P2
    • Resolution: Unresolved
    • Affects Version/s: 9.0.1
    • Fix Version/s: 11
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      We are running annotation processors that use javax.lang.model.util.Elements#getTypeElement a lot. It seems that the performance regressed almost 1000x when using --release 9 instead of --release 8 on the recent JDK9.

      Test Code:

      @SupportedAnnotationTypes(value = "mypackage.MyAnnotation")
      public class MyAnnotationProcessor extends AbstractProcessor {

      @Override
      public SourceVersion getSupportedSourceVersion() {
      return SourceVersion.latest();
      }

          @Override
          public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
              String name = "mypackage.MyClass";
              Elements elementUtils = processingEnv.getElementUtils();
              long time = System.currentTimeMillis();
              for (int i = 0; i < 10000; i++) {
                  elementUtils.getTypeElement(name);
              }
              System.out.println((System.currentTimeMillis() - time) + "ms");
              return false;
          }

      }

      I've tested this also with a single iteration, where --release 8 took 0ms and --release 9 was 18ms.

      Steps to reproduce on Linux Ubuntu:
      unpack MyAnnotationProcessor.tar.gz
      set JAVA_HOME to JDK 9.0.1
      sh ./run.sh

      The expected output is:
      Running with --release 8
      71ms
      27ms
      Running with --release 9
      2325ms
      1711ms

        Attachments

          Activity

            People

            • Assignee:
              darcy Joe Darcy
              Reporter:
              chumer Christian Humer
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: