1. Cayenne
  2. CAY-1667

Expression parser performance optimization


    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 3.1M3
    • Fix Version/s: 3.1B1
    • Component/s: Core Library
    • Labels:


      Inspecting some profiling data from a customer I see an inefficiency inside Expression.fromString. It was actually discovered inside Ordering class, that compiles path string on demand, so it affects even the queries that do not use 'fromString', as well Orderings created for in-memory sorting. There are 2 culprits in JavaCharStream that is generated by javaCC (although JavaCharStream is not a part of the parser, so we can probaby change the code on top of the generated class) :

      1. JavaCharStream.fillBuff() has throw new; that is caught right in that same method (!!!) Throwable.fillStackTrace() shows as a "hot spot" in the profile. There should be a better way to handle if/else condition

      2. Expression.fromString -> new ExpressionParser(Reader) -> new JavaCharStream(Reader, int startline, int startcolumn)
      JavaCharStream constructor is heavy and shows as a hotspot. For one thing it creates 4 int/char buffers with size of 4096 each. I don't think we have such long expressions ever, and don't need all this memory. Moreover we can probably guess the max needed buffer size from the original String length. My guess is that most expressions are under 100-300 chars. Certainly true for the orderings.


        No work has yet been logged on this issue.


          • Assignee:
            Andrus Adamchik
            Andrus Adamchik
          • Votes:
            0 Vote for this issue
            0 Start watching this issue


            • Created: