commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dmitri Blinov (JIRA)" <j...@apache.org>
Subject [jira] [Created] (JEXL-215) JexlEngine.createInfo() is redundantly called when debug and caching is enabled leading to sub-optimal performance
Date Fri, 26 Aug 2016 13:59:20 GMT
Dmitri Blinov created JEXL-215:
----------------------------------

             Summary: JexlEngine.createInfo() is redundantly called when debug and caching
is enabled leading to sub-optimal performance
                 Key: JEXL-215
                 URL: https://issues.apache.org/jira/browse/JEXL-215
             Project: Commons JEXL
          Issue Type: Improvement
    Affects Versions: 3.0
            Reporter: Dmitri Blinov


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 
{code}
        if (info == null && debug) {
            info = createInfo();
        }
{code}

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

{code}
    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;
    }
{code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message