0

In OGNL, it is recommended to parse expressions that are reused in order to improve performance.

When consulting the API, I also noticed that there is a compileExpression method:

After searching thoroughly for information on compilation vs parsing, the only article I could find is part of the Struts documentation, and mentions how to do it, but not what it does compared to parsing.

Under what conditions should you use compilation instead of parsing alone, and are there significant performance benefits to be gained from compiling an expression compared to simply parsing that same expression?

From the method signatures, it appears that Ognl.parseExpression() produces an input-independent object, but Ognl.compileExpression() produces an object that depends upon the given input (root and context). Is this correct?

jr.
  • 1,699
  • 14
  • 31

1 Answers1

2

That http://struts.apache.org/release/2.3.x/docs/ognl-expression-compilation.html link is pretty old and I'm not sure if it's outdated or not but it's the only real documentation I ever wrote on how to use the javassist-based expression JIT code.

It's only a relevant concern if your own use of something either directly or indirectly using ognl shows a performance hit in that area. The normal expression evaluation mechanism is probably more than adequate for most needs but this extra step turns what is basically a java reflection chain of invocation calls into pure java equivalents so it eliminates almost entirely any hit you might otherwise incur using OGNL because of reflection.

Really, if you aren't sure if you need it you probably don't. Sorry I never got around to integrating the concept thoroughly into OGNL without so much scary looking extra work. Probably would've been best as an optional configuration setting in OGNL that was turned off or on but .. Feel free to fork on github if you want. =)

jkuhnert
  • 94
  • 4
  • The Ognl.compileExpression() method depends on the root and context - does this mean that the Node returned is only for evaluating that same input? Ognl.parseExpression() seems to be the way to go since it appears to be input independent. Is this correct? If you could factor the answer(s) to the above two questions into your answer, I'll give you the magic tick. I'll edit my question to be a bit clearer too. Thanks for the clear explanation on the underlying processes involved when compiling and parsing. – jr. Jun 30 '13 at 07:11
  • compileExpression() should be just as generic wrt input/output over the same "types" of data as parseExpression() – jkuhnert Aug 26 '13 at 20:54