Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
3.1
-
None
Description
In profiling my JEXL-enabled application, I observed that nearly 10% of the execution time is spend filling in the JexlExpression#Return class's stack. As far as I can tell, the Return object's stack is not used by JEXL and so does not need to be present.
I read about an optimization technique where you override fillInStackTrace() to be a no-op when using exceptions for control flow. As I understand it, this practice was codified into Java 7 with the "writableStackTrace" parameter to Throwable's ctor that lets you disable filling in the stack trace.
For Java 6 and below, this is as easy as adding this to the body of Return.
@Override public Throwable fillInStackTrace() { // Don't fill in the stack. It's not needed for return values. return this; }
In private testing, this has the expected effect: my application finishes in ~10% less time and all unit tests continue to pass.
There's a discussion of this on stack overflow:
https://stackoverflow.com/questions/1836164/override-fillinstacktrace-for-control-flow-performance
There's a better discussion in the answer given to:
https://stackoverflow.com/questions/11434431/exception-without-stack-trace-in-java