commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jeff Ichnowski (JIRA)" <j...@apache.org>
Subject [jira] Updated: (JEXL-97) JEXL parses long expressions with lots of parenthesis slowly
Date Thu, 11 Feb 2010 01:28:31 GMT

     [ https://issues.apache.org/jira/browse/JEXL-97?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Jeff Ichnowski updated JEXL-97:
-------------------------------

    Description: 
JEXL's parser uses an unbounded JavaCC LOOKAHEAD to distinguish assignment expressions from
other expressions.  The result is certain expressions take exponential time to parse.  The
example snippet below demonstrates the problem.  On my machine parsing the expression below
takes ~120 seconds.  Changing the parser to remove the LOOKAHEAD can get this to parse in
milliseconds.  The lookahead appears to be in all versions of the parser source.

import org.apache.commons.jexl.Expression;
import org.apache.commons.jexl.ExpressionFactory;

public class SlowParse {

    public static void main(String[] args) throws Exception {

        String input = 

            "(((((((((((((((((((((((((z+y)/x)*w)-v)*u)/t)-s)*r)/q)+p)-o)*n)-m)+l)*k)+j)/i)+h)*g)+f)/e)+d)-c)/b)+a)";

        // Make sure everything is loaded...

        Expression expr = ExpressionFactory.createExpression(input);

        long start = System.nanoTime();

        expr = ExpressionFactory.createExpression(input);

        long end = System.nanoTime();

        System.out.printf("Parse took %.1f seconds\n", (end-start)/1e+9);

    }

}

  was:
JEXL's parser uses an unbounded JavaCC LOOKAHEAD to distinguish assignment expressions from
other expressions.  The result is certain expressions take exponential time to parse.  The
example snippet below demonstrates the problem.  On my machine parsing the expression below
takes ~120 seconds.  Changing the parser to remove the LOOKAHEAD can get this to parse in
milliseconds.  The lookahead appears to be in all versions of the parser source.

import org.apache.commons.jexl.Expression;
import org.apache.commons.jexl.ExpressionFactory;

public class SlowParse {
    public static void main(String[] args) throws Exception {
        String input = 
            "(((((((((((((((((((((((((z+y)/x)*w)-v)*u)/t)-s)*r)/q)+p)-o)*n)-m)+l)*k)+j)/i)+h)*g)+f)/e)+d)-c)/b)+a)";

        // Make sure everything is loaded...
        Expression expr = ExpressionFactory.createExpression(input);

        long start = System.nanoTime();
        expr = ExpressionFactory.createExpression(input);
        long end = System.nanoTime();
        System.out.printf("Parse took %.1f seconds\n", (end-start)/1e+9);
    }
}


> JEXL parses long expressions with lots of parenthesis slowly
> ------------------------------------------------------------
>
>                 Key: JEXL-97
>                 URL: https://issues.apache.org/jira/browse/JEXL-97
>             Project: Commons JEXL
>          Issue Type: Bug
>    Affects Versions: 2.0, 1.1, 1.0
>         Environment: Java
>            Reporter: Jeff Ichnowski
>            Priority: Minor
>         Attachments: proposed.patch
>
>
> JEXL's parser uses an unbounded JavaCC LOOKAHEAD to distinguish assignment expressions
from other expressions.  The result is certain expressions take exponential time to parse.
 The example snippet below demonstrates the problem.  On my machine parsing the expression
below takes ~120 seconds.  Changing the parser to remove the LOOKAHEAD can get this to parse
in milliseconds.  The lookahead appears to be in all versions of the parser source.
> import org.apache.commons.jexl.Expression;
> import org.apache.commons.jexl.ExpressionFactory;
> public class SlowParse {
>     public static void main(String[] args) throws Exception {
>         String input = 
>             "(((((((((((((((((((((((((z+y)/x)*w)-v)*u)/t)-s)*r)/q)+p)-o)*n)-m)+l)*k)+j)/i)+h)*g)+f)/e)+d)-c)/b)+a)";
>         // Make sure everything is loaded...
>         Expression expr = ExpressionFactory.createExpression(input);
>         long start = System.nanoTime();
>         expr = ExpressionFactory.createExpression(input);
>         long end = System.nanoTime();
>         System.out.printf("Parse took %.1f seconds\n", (end-start)/1e+9);
>     }
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message