pug4j icon indicating copy to clipboard operation
pug4j copied to clipboard

Add customizability to JaxelEngine

Open Selaron opened this issue 1 year ago • 0 comments

In order to play with performance relevant options I'd like to be able to customize more properties of the JexlExpressionHandler:

Including:

  1. cache size (max number of cached expressions; default 5000)
  2. cacheThreshold (max length of expressions to be cached; default 64)
  3. debug (whether or not to provide debug info; default true)

While the advantage of being able to play around with 1 and 2 is quite self explaining, 3 maybe not:

As debug is enabled by default and all these options do not seem to be customizable easily without implementing a very custom ExpressionHandler, each rendering (huge) pug templates results in thousands of these executions:

    public JexlInfo() {
       final StackTraceElement[] stack = new Throwable().getStackTrace();
       ...
     }

which produces a lot of full stack traces of arbitrary length and is likely to hit the rendering speed.

As a simple solution maybe it would be enough to have the method de.neuland.pug4j.expression.JexlExpressionHandler#getJexlEngine refactored to use a PugJexlBuilder received from a protected method which we can override like:

@Override
protected PugJexlBuilder getPugJexlBuilder() {
   PugJexlBuilder builder = super.getPugJexlBuilder();
   builder.debug(false);
   builder.cache(10000);
   builder.cacheThreshold(256);
   return builder;
}

Selaron avatar Nov 14 '23 21:11 Selaron