Grails
  1. Grails
  2. GRAILS-8050

GormStaticApi.methodMissing gets called for every invocation

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-M2
    • Fix Version/s: 2.0-RC1
    • Component/s: None
    • Labels:
      None

      Description

      GormStaticApi.methodMissing gets called for every invocation at least for some finders.

      One of the methods is with the signature "DomainClass.findByPropertyName(Long value)".

      The code in GormStaticApi.methodMissing that registers the metamethod to the metaclass has no effect:

              // register the method invocation for next time
              synchronized(this) {
                  mc.static."$methodName" = { List varArgs ->
                      method.invoke(cls, methodName, varArgs)
                  }
              }
      

      In a performance test of one of our real Grails projects, YJP shows that significant amount of time (about 20%) is spent in this method.

        Issue Links

          Activity

          Hide
          Lari Hotari added a comment -

          Perhaps "List varArgs" should be "Object[] varArgs"? See http://groovy.codehaus.org/Using+methodMissing+and+propertyMissing .

          Show
          Lari Hotari added a comment - Perhaps "List varArgs" should be "Object[] varArgs"? See http://groovy.codehaus.org/Using+methodMissing+and+propertyMissing .
          Hide
          Lari Hotari added a comment -

          I think Grails 1.3.x also has the same bug.

          Show
          Lari Hotari added a comment - I think Grails 1.3.x also has the same bug.
          Hide
          Lari Hotari added a comment - - edited

          This piece of code for registering method in metaclass works for Grails 2.0 :

                  synchronized(this) {
                      mc.static."$methodName" = { Object[] varArgs ->
                          method.invoke(cls, methodName, varArgs ? varArgs[0] : varArgs)
                      }
                  }
          
          Show
          Lari Hotari added a comment - - edited This piece of code for registering method in metaclass works for Grails 2.0 : synchronized ( this ) { mc. static . "$methodName" = { Object [] varArgs -> method.invoke(cls, methodName, varArgs ? varArgs[0] : varArgs) } }
          Hide
          Graeme Rocher added a comment -

          That assumes that there is only ever one argument to the method

          Show
          Graeme Rocher added a comment - That assumes that there is only ever one argument to the method
          Hide
          Lari Hotari added a comment -

          Yes, the argument is always a list (for some reason?) and it has to be "unwrapped". Could you try it?

          Show
          Lari Hotari added a comment - Yes, the argument is always a list (for some reason?) and it has to be "unwrapped". Could you try it?
          Show
          Graeme Rocher added a comment - Fixed by https://github.com/SpringSource/grails-data-mapping/commit/44031e133d3f7d3c93f575c38b4038bee246292c

            People

            • Assignee:
              Graeme Rocher
              Reporter:
              Lari Hotari
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development