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

Extreme performance problem when calling closures using 'shorthand' notation

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Won't Fix
    • 1.0
    • 1.1-rc-1
    • None
    • None
    • Linux: blackdown-j2sdk1.4.2_03 and sun's jdk1.5.0_09
      Windows XP Pro: jdk1.5.0_10

    Description

      When I define a closure and store it to a variable, according to groovy's documentation I can use two ways of calling that closure: closure.call(args) or closure(args). There is a great performance difference between these calls though. The difference consists of:

      2 calls to new MissingPropertyException
      2 calls to new MissingMethodException
      2 calls to InvokeHelper.format(Object arguments, boolean verbose)
      12 calls to arg.replaceAll (InvokeHelper:line 600)

      One problem is the arg.replaceAll in InvokeHelper.format. Formatting the exceptions that are catched inside groovy is totally useless and causes extremely big performance loss. Removing calls to InvokerHelper improves performance a lot. Below an example of the two cases and how they work in different versions of groovy:

      test.groovy:
      ------------------------------------
      closure = { number ->
      test = number + 1;
      }

      start = java.lang.System.currentTimeMillis()
      for (i in 0..100000) {
      closure(1)
      }
      end = java.lang.System.currentTimeMillis()
      test1 = end - start

      start = java.lang.System.currentTimeMillis()
      for (i in 0..100000) {
      closure.call(1)
      }
      end = java.lang.System.currentTimeMillis()
      test2 = end - start

      println "test1: $test1"
      println "test2: $test2"
      --------------------------------------

      tested with: blackdown-j2sdk1.4.2_03 and sun's jdk1.5.0_09

      groovy-1.0-jsr-04/bin/groovy test.groovy
      test1: 573
      test2: 541

      groovy-1.0-jsr-06/bin/groovy test.groovy
      test1: 30370
      test2: 654

      groovy-1.0/bin/groovy test.groovy
      test1: 8455
      test2: 615

      groovy-1.0-modified/bin/groovy test.groovy
      test1: 7653
      test2: 620

      groovy-1.0-modified is the same as 1.0, but MissingMethodException's call to InvokerHelper's methods were removed.

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            mthalttu Mikko Halttunen
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: