Uploaded image for project: 'Commons JEXL'
  1. Commons JEXL
  2. JEXL-215

JexlEngine.createInfo() is redundantly called when debug and caching is enabled leading to sub-optimal performance

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.0
    • Fix Version/s: 3.1
    • Labels:
      None

      Description

      The following two methods Engine.createScript() and Engine.createExpression() are calling JexlEngine.createInfo() when debug mode is enabled and JexlInfo is not provided. But if caching is enabled the method Engine.parse() will not use provided JexlInfo if the requested statement is already in the cache. This leads to sub-optimal performance, in my measurements up to 100 times slower. The suggestion is to refactor by removing the following code

              if (info == null && debug) {
                  info = createInfo();
              }
      

      from methods Engine.createScript() and Engine.createExpression() and adding to the method Engine.parse() after the cache check, like this

          protected ASTJexlScript parse(JexlInfo info, String src, Scope scope, boolean registers, boolean expression) {
              final boolean cached = src.length() < cacheThreshold && cache != null;
              ASTJexlScript script;
              synchronized (parser) {
                  if (cached) {
                      script = cache.get(src);
                      if (script != null) {
                          Scope f = script.getScope();
                          if ((f == null && scope == null) || (f != null && f.equals(scope))) {
                              return script;
                          }
                      }
                  }
      
                  if (info == null && debug) {
                      info = createInfo();
                  }
      
                  script = parser.parse(info, src, scope, registers, expression);
                  if (cached) {
                      cache.put(src, script);
                  }
              }
              return script;
          }
      

        Attachments

          Activity

            People

            • Assignee:
              henrib Henri Biestro
              Reporter:
              dmitri_blinov Dmitri Blinov
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: