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

Method calls are 2-3 times slower with "indy" option enabled

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Not A Problem
    • Affects Version/s: 2.1.8, 2.1.9
    • Fix Version/s: None
    • Component/s: Compiler
    • Labels:
    • Environment:
      Ubuntu 13.10 64
      Java(TM) SE Runtime Environment (build 1.7.0_40-b43)

      Description

      When "indy" parameter is specified for compiler, resulted compiled script is 2-3 times slower than the one without "indy". For example, consider this snippet:

      class Test1 {
          def random = new Random()
          def sum = 0;
      
          def stub(String s) {
              sum += random.nextInt()
          }
          def methodMissing(String name, args) {
              stub("stub")
          }
      }
      
      def count = 100000
      for (z in 1..10) {
          def t = new Test1()
          def time = 0
          for (i in 1..count) {
              def cur = System.nanoTime()
              t.someMethod()
              time += System.nanoTime() - cur
          }
          printf('missing: %d total, %.2f avg      %d\n', time, time / count, t.sum)
      }
      

      I removed "invokeMethod" and direct method calls for simplicity, but they have the same impact on performance. However there is full version in attachment.
      Also in a debugger I can see that "indy"ed version has much bigger call stack compared to normal version:
      at actors.Test2.methodMissing(player.groovy:30)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java:-1)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
      at groovy.lang.MetaClassImpl.invokeMissingMethod(MetaClassImpl.java:837)
      at groovy.lang.MetaClassImpl.invokePropertyOrMissing(MetaClassImpl.java:1134)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1087)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909)
      at java.lang.invoke.LambdaForm$DMH.invokeSpecial_LLLL_L(LambdaForm$DMH:-1)
      at java.lang.invoke.LambdaForm$DMH.invokeSpecial_LLLLL_L(LambdaForm$DMH:-1)
      at java.lang.invoke.LambdaForm$NamedFunction.invoke_LLLLL_L(LambdaForm.java:1112)
      at java.lang.invoke.LambdaForm$DMH.invokeStatic_LL_L(LambdaForm$DMH:-1)
      at java.lang.invoke.LambdaForm$NamedFunction.invokeWithArguments(LambdaForm.java:1136)
      at java.lang.invoke.LambdaForm.interpretName(LambdaForm.java:625)
      at java.lang.invoke.LambdaForm.interpretWithArguments(LambdaForm.java:604)
      at java.lang.invoke.LambdaForm$LFI.interpret_L(LambdaForm$LFI:-1)
      at java.lang.invoke.LambdaForm$NamedFunction.invoke_LLL_L(LambdaForm.java:1102)
      at java.lang.invoke.LambdaForm$DMH.invokeStatic_LL_L(LambdaForm$DMH:-1)
      at java.lang.invoke.LambdaForm$NamedFunction.invokeWithArguments(LambdaForm.java:1136)
      at java.lang.invoke.LambdaForm.interpretName(LambdaForm.java:625)
      at java.lang.invoke.LambdaForm.interpretWithArguments(LambdaForm.java:604)
      at java.lang.invoke.LambdaForm$LFI.interpret_L(LambdaForm$LFI:-1)
      at java.lang.invoke.LambdaForm$MH.invokeExact_MT(LambdaForm$MH:-1)
      at java.lang.invoke.MethodHandleImpl$GuardWithCatch.invoke_L3(MethodHandleImpl.java:639)
      at java.lang.invoke.LambdaForm$DMH.invokeSpecial_LLLL_L(LambdaForm$DMH:-1)
      at java.lang.invoke.LambdaForm$DMH.invokeSpecial_LLLLL_L(LambdaForm$DMH:-1)
      at java.lang.invoke.LambdaForm$NamedFunction.invoke_LLLLL_L(LambdaForm.java:1112)
      at java.lang.invoke.LambdaForm$DMH.invokeStatic_LL_L(LambdaForm$DMH:-1)
      at java.lang.invoke.LambdaForm$NamedFunction.invokeWithArguments(LambdaForm.java:1136)
      at java.lang.invoke.LambdaForm.interpretName(LambdaForm.java:625)
      at java.lang.invoke.LambdaForm.interpretWithArguments(LambdaForm.java:604)
      at java.lang.invoke.LambdaForm$LFI.interpret_L(LambdaForm$LFI:-1)
      at java.lang.invoke.LambdaForm$NamedFunction.invoke_LLL_L(LambdaForm.java:1102)
      at java.lang.invoke.LambdaForm$DMH.invokeStatic_LL_L(LambdaForm$DMH:-1)
      at java.lang.invoke.LambdaForm$NamedFunction.invokeWithArguments(LambdaForm.java:1136)
      at java.lang.invoke.LambdaForm.interpretName(LambdaForm.java:625)
      at java.lang.invoke.LambdaForm.interpretWithArguments(LambdaForm.java:604)
      at java.lang.invoke.LambdaForm$LFI.interpret_L(LambdaForm$LFI:-1)
      at java.lang.invoke.LambdaForm$NamedFunction.invoke_LL_L(LambdaForm.java:1097)
      at java.lang.invoke.LambdaForm$DMH.invokeStatic_LL_L(LambdaForm$DMH:-1)
      at java.lang.invoke.LambdaForm$NamedFunction.invokeWithArguments(LambdaForm.java:1136)
      at java.lang.invoke.LambdaForm.interpretName(LambdaForm.java:625)
      at java.lang.invoke.LambdaForm.interpretWithArguments(LambdaForm.java:604)
      at java.lang.invoke.LambdaForm$LFI.interpret_L(LambdaForm$LFI:-1)
      at java.lang.invoke.LambdaForm$MH.invokeExact_MT(LambdaForm$MH:-1)
      at java.lang.invoke.MethodHandleImpl$GuardWithCatch.invoke_L1(MethodHandleImpl.java:621)
      at java.lang.invoke.LambdaForm$DMH.invokeSpecial_LL_L(LambdaForm$DMH:-1)
      at java.lang.invoke.LambdaForm$BMH.reinvoke(LambdaForm$BMH:-1)
      at java.lang.invoke.LambdaForm$DMH.invokeSpecial_LL_L(LambdaForm$DMH:-1)
      at java.lang.invoke.LambdaForm$NamedFunction.invoke_LL_L(LambdaForm.java:1097)
      at java.lang.invoke.LambdaForm$DMH.invokeStatic_LL_L(LambdaForm$DMH:-1)
      at java.lang.invoke.LambdaForm$NamedFunction.invokeWithArguments(LambdaForm.java:1136)
      at java.lang.invoke.LambdaForm.interpretName(LambdaForm.java:625)
      at java.lang.invoke.LambdaForm.interpretWithArguments(LambdaForm.java:604)
      at java.lang.invoke.LambdaForm$LFI.interpret_L(LambdaForm$LFI:-1)
      at java.lang.invoke.LambdaForm$DMH.invokeSpecial_LL_L(LambdaForm$DMH:-1)
      at java.lang.invoke.LambdaForm$NamedFunction.invoke_LL_L(LambdaForm.java:1097)
      at java.lang.invoke.LambdaForm$DMH.invokeStatic_LL_L(LambdaForm$DMH:-1)
      at java.lang.invoke.LambdaForm$NamedFunction.invokeWithArguments(LambdaForm.java:1136)
      at java.lang.invoke.LambdaForm.interpretName(LambdaForm.java:625)
      at java.lang.invoke.LambdaForm.interpretWithArguments(LambdaForm.java:604)
      at java.lang.invoke.LambdaForm$LFI.interpret_L(LambdaForm$LFI:-1)
      at java.lang.invoke.LambdaForm$DMH.invokeSpecial_LL_L(LambdaForm$DMH:-1)
      at java.lang.invoke.LambdaForm$NamedFunction.invoke_LL_L(LambdaForm.java:1097)
      at java.lang.invoke.LambdaForm$DMH.invokeStatic_LL_L(LambdaForm$DMH:-1)
      at java.lang.invoke.LambdaForm$NamedFunction.invokeWithArguments(LambdaForm.java:1136)
      at java.lang.invoke.LambdaForm.interpretName(LambdaForm.java:625)
      at java.lang.invoke.LambdaForm.interpretWithArguments(LambdaForm.java:604)
      at java.lang.invoke.LambdaForm$LFI.interpret_L(LambdaForm$LFI:-1)
      at java.lang.invoke.LambdaForm$NamedFunction.invoke_L_L(LambdaForm.java:1092)
      at java.lang.invoke.LambdaForm$DMH.invokeStatic_LL_L(LambdaForm$DMH:-1)
      at java.lang.invoke.LambdaForm$NamedFunction.invokeWithArguments(LambdaForm.java:1136)
      at java.lang.invoke.LambdaForm.interpretName(LambdaForm.java:625)
      at java.lang.invoke.LambdaForm.interpretWithArguments(LambdaForm.java:604)
      at java.lang.invoke.LambdaForm$LFI.interpret_L(LambdaForm$LFI:-1)
      at java.lang.invoke.LambdaForm$MH.invokeExact_MT(LambdaForm$MH:-1)
      at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:212)
      at java.lang.invoke.LambdaForm$DMH.invokeStatic_LLLILLLLL_L(LambdaForm$DMH:-1)
      at java.lang.invoke.LambdaForm$DMH.invokeSpecial_LLLLILLLLL_L(LambdaForm$DMH:-1)
      at java.lang.invoke.LambdaForm$NFI.invoke_LLLLILLLLL_L(LambdaForm$NFI:-1)
      at java.lang.invoke.LambdaForm$DMH.invokeStatic_LL_L(LambdaForm$DMH:-1)
      at java.lang.invoke.LambdaForm$NamedFunction.invokeWithArguments(LambdaForm.java:1136)
      at java.lang.invoke.LambdaForm.interpretName(LambdaForm.java:625)
      at java.lang.invoke.LambdaForm.interpretWithArguments(LambdaForm.java:604)
      at java.lang.invoke.LambdaForm$LFI.interpret_L(LambdaForm$LFI:-1)
      at java.lang.invoke.LambdaForm$NamedFunction.invoke_L_L(LambdaForm.java:1092)
      at java.lang.invoke.LambdaForm$DMH.invokeStatic_LL_L(LambdaForm$DMH:-1)
      at java.lang.invoke.LambdaForm$NamedFunction.invokeWithArguments(LambdaForm.java:1136)
      at java.lang.invoke.LambdaForm.interpretName(LambdaForm.java:625)
      at java.lang.invoke.LambdaForm.interpretWithArguments(LambdaForm.java:604)
      at java.lang.invoke.LambdaForm$LFI.interpret_L(LambdaForm$LFI:-1)
      at java.lang.invoke.LambdaForm$MH.linkToCallSite(LambdaForm$MH:-1)

      compared to just about 10 lines in non-indy version.

      Java code used for runnnig script:

      GroovyScriptEngine engine = new GroovyScriptEngine("scripts");
      Binding binding = new Binding();
      Map<String, Boolean> options = engine.getConfig().getOptimizationOptions();
      options.put("indy", Boolean.TRUE);
      Object result = engine.run("actors/player.groovy", binding);
      

        Attachments

        1. example.groovy
          2 kB
          Andrew Grabko

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                ttrevan Andrew Grabko
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: