You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Jeff Ichnowski (JIRA)" <ji...@apache.org> on 2010/02/11 02:20:30 UTC

[jira] Created: (JEXL-97) JEXL parses long expressions with lots of parenthesis slowly

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: 1.0, 1.1, 2.0
         Environment: Java
            Reporter: Jeff Ichnowski
            Priority: Minor


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.


[jira] Commented: (JEXL-97) JEXL parses long expressions with lots of parenthesis slowly

Posted by "Jeff Ichnowski (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/JEXL-97?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12832675#action_12832675 ] 

Jeff Ichnowski commented on JEXL-97:
------------------------------------

Thanks for the quick attention!  Confirmed on my end too.  My apologies for not being clear that it was limited to 1.x as far as we've tried.  Our problem is in 1.1 and we've got too much tied into it currently to do a major upgrade quickly.  Is there a possibility of a 1.1 patch?

The LOOKAHEAD and recognized syntax in JEXL 2.0 is much simpler.  Perhaps a 1.1 patch release (if planned) could use the 2.0 structure instead of the patch I proposed above.  Unfortunately it would break anything that depended on expressions like  "(a) = 1" being recognized (which currently is by 1.1).

{code:title=JEXL 2.0 Expression}
void Expression() #void : {}
{
    LOOKAHEAD( Reference() "=" ) Assignment()
|
    ConditionalExpression()
}
{code}

{code:title=JEXL 1.1 Expression with Problem}
void Expression() : {}
{
    LOOKAHEAD( PrimaryExpression() "=" ) Assignment()
|
    ConditionalOrExpression()
}
{code}

{code:title=JEXL 1.0 Alternate Fix}
void Expression() : {}
{
    LOOKAHEAD( Reference() "=" ) Assignment()
|
    ConditionalOrExpression()
}
{code}


> 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: 1.1
>         Environment: Java
>            Reporter: Jeff Ichnowski
>            Priority: Minor
>             Fix For: 2.0
>
>         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.


[jira] Updated: (JEXL-97) JEXL parses long expressions with lots of parenthesis slowly

Posted by "Henri Biestro (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/JEXL-97?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Biestro updated JEXL-97:
------------------------------

    Fix Version/s:     (was: 2.0)
                   2.0.1

> 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: 1.1
>         Environment: Java
>            Reporter: Jeff Ichnowski
>            Priority: Minor
>             Fix For: 2.0.1
>
>         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.


[jira] Issue Comment Edited: (JEXL-97) JEXL parses long expressions with lots of parenthesis slowly

Posted by "Henri Biestro (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/JEXL-97?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12832418#action_12832418 ] 

Henri Biestro edited comment on JEXL-97 at 2/11/10 8:19 AM:
------------------------------------------------------------

I've been trying to reproduce this behavior on 2.x trunk with this code added as a method in IssuesTest.java:
{code}
    public void test97() throws Exception {
        JexlContext ctxt = new MapContext();
        for(char v = 'a'; v <= 'z'; ++v) {
            ctxt.set(Character.toString(v), 10);
        }
        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)";

        JexlEngine jexl = new JexlEngine();
        Expression script;
        // Make sure everything is loaded...
        long start = System.nanoTime();
        script = jexl.createExpression(input);
        Object value = script.evaluate(ctxt);
        assertEquals(Integer.valueOf(11), value);
        long end = System.nanoTime();
        System.out.printf("Parse took %.3f seconds\n", (end-start)/1e+9);
    }
{code}

Runs in .003s on my box (os x, 2.8Ghz, jdk1.5 and jdk1.6).
Checked original code in 2.0 using jexl-compat lib and the performance is the same (aka normal).

I've been able to reproduce it with JEXL 1; it seems to be fixed in 2.0.



      was (Author: henrib):
    I've been trying to reproduce this behavior on 2.x trunk with this code added as a method in IssuesTest.java:
{code}
    public void test97() throws Exception {
        JexlContext ctxt = new MapContext();
        for(char v = 'a'; v <= 'z'; ++v) {
            ctxt.set(Character.toString(v), 10);
        }
        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)";

        JexlEngine jexl = new JexlEngine();
        Expression script;
        // Make sure everything is loaded...
        long start = System.nanoTime();
        script = jexl.createExpression(input);
        Object value = script.evaluate(ctxt);
        assertEquals(Integer.valueOf(11), value);
        long end = System.nanoTime();
        System.out.printf("Parse took %.3f seconds\n", (end-start)/1e+9);
    }
{code}

Runs in .003s on my box (os x, 2.8Ghz, jdk1.5 and jdk1.6).
Can you check again and/or upload a modified test that exhibits the performance issue you describe?
The code you originally posted can only run on JEXL1.x (ExpressionFactory does not exist in jexl2).
Thanks

  
> 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.


[jira] Updated: (JEXL-97) JEXL parses long expressions with lots of parenthesis slowly

Posted by "Jeff Ichnowski (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/JEXL-97?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

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

    Attachment: proposed.patch

> 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.


[jira] Closed: (JEXL-97) JEXL parses long expressions with lots of parenthesis slowly

Posted by "Henri Biestro (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/JEXL-97?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Biestro closed JEXL-97.
-----------------------------


> 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: 1.1
>         Environment: Java
>            Reporter: Jeff Ichnowski
>            Priority: Minor
>             Fix For: 2.0
>
>         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.


[jira] Resolved: (JEXL-97) JEXL parses long expressions with lots of parenthesis slowly

Posted by "Henri Biestro (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/JEXL-97?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Biestro resolved JEXL-97.
-------------------------------

       Resolution: Fixed
    Fix Version/s:     (was: 2.0.1)
                   2.0

The 2.0 version fixes the issue; no foreseeable 1.1. version planned.

> 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: 1.1
>         Environment: Java
>            Reporter: Jeff Ichnowski
>            Priority: Minor
>             Fix For: 2.0
>
>         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.


[jira] Updated: (JEXL-97) JEXL parses long expressions with lots of parenthesis slowly

Posted by "Henri Biestro (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/JEXL-97?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Biestro updated JEXL-97:
------------------------------

    Affects Version/s:     (was: 2.0)
                           (was: 1.0)
        Fix Version/s: 2.0

Per previous tests, pb shows up in JEXL1.x but is fixed in JEXL 2.x.

> 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: 1.1
>         Environment: Java
>            Reporter: Jeff Ichnowski
>            Priority: Minor
>             Fix For: 2.0
>
>         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.


[jira] Updated: (JEXL-97) JEXL parses long expressions with lots of parenthesis slowly

Posted by "Jeff Ichnowski (JIRA)" <ji...@apache.org>.
     [ 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.


[jira] Commented: (JEXL-97) JEXL parses long expressions with lots of parenthesis slowly

Posted by "Henri Biestro (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/JEXL-97?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12832418#action_12832418 ] 

Henri Biestro commented on JEXL-97:
-----------------------------------

I've been trying to reproduce this behavior on 2.x trunk with this code added as a method in IssuesTest.java:
{code}
    public void test97() throws Exception {
        JexlContext ctxt = new MapContext();
        for(char v = 'a'; v <= 'z'; ++v) {
            ctxt.set(Character.toString(v), 10);
        }
        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)";

        JexlEngine jexl = new JexlEngine();
        Expression script;
        // Make sure everything is loaded...
        long start = System.nanoTime();
        script = jexl.createExpression(input);
        Object value = script.evaluate(ctxt);
        assertEquals(Integer.valueOf(11), value);
        long end = System.nanoTime();
        System.out.printf("Parse took %.3f seconds\n", (end-start)/1e+9);
    }
{code}

Runs in .003s on my box (os x, 2.8Ghz, jdk1.5 and jdk1.6).
Can you check again and/or upload a modified test that exhibits the performance issue you describe?
The code you originally posted can only run on JEXL1.x (ExpressionFactory does not exist in jexl2).
Thanks


> 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.


[jira] Updated: (JEXL-97) JEXL parses long expressions with lots of parenthesis slowly

Posted by "Jeff Ichnowski (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/JEXL-97?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

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

    Attachment: proposed.patch

Attaching a proposal for a patch to fix this issue.  The change will make the parser slightly more permissive in what it allows for the left-hand side of an assignment expression.  If this is not acceptable, we could also add a check during or after the parse, to make sure assignment expressions are correct.

> 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.


[jira] Updated: (JEXL-97) JEXL parses long expressions with lots of parenthesis slowly

Posted by "Jeff Ichnowski (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/JEXL-97?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

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

    Attachment:     (was: proposed.patch)

> 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
>
> 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.


[jira] Commented: (JEXL-97) JEXL parses long expressions with lots of parenthesis slowly

Posted by "Henri Biestro (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/JEXL-97?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12833085#action_12833085 ] 

Henri Biestro commented on JEXL-97:
-----------------------------------

There is no "plan" in getting a new 1.1 out AFAIK ; 2.0 is supposed to replace it (hopefully with some added benefits).
You always have the choice of a local 1.1 fix / release if you are in an emergency situation.

May I suggest you have a closer look at 2.0 and assess how much you miss from 1.1 ? The jexl-compat lib might give you a quick evaluation path.

If you can elaborate what you mean by "too much tied into it" in a post to the mailing list, you'll most likely get advice/help on migrating/reimplementing features .

> 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: 1.1
>         Environment: Java
>            Reporter: Jeff Ichnowski
>            Priority: Minor
>             Fix For: 2.0
>
>         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.