L3 - Default
When profiling a process we found a performance problem inside `ExpressionFactory.newInstance`. This method uses some complex logic of looking into `META-INF/services`, the home directory or a system property to decide which implementation to instantiate using reflections.
Normally this should not be a problem since the factory could be reused. There is however one constellation where this method gets invoked repeatedly: When an EL expressions uses method calls an ExpressionFactory is created to coerce argument types. This instance is then cached on the `BeanELResolver`, but this cache is not reused across subprocesses.
A testcase that can be run in a profiler is available at <https://github.com/jhorstmann/camunda-engine-unittest/tree/expression-factory-performance>. A screenshot of a profiling run is attached. The effect could be more pronounced in a bigger application with larger classpath or when running in a container with several class loaders.
There are several possible improvements:
- Argument type coercion would not be needed for methods without arguments
- The BeanELResolver could be reused across ELContexts (ELContext itself is not threadsafe, but the resolvers should be. This might give more performance benefits since BeanELResolver contains a cache of bean properties.
- The lookup inside ExpressionFactory.newInstance could be simplified if it not actually supported to replace the expression language used inside the engine. This is the approach I'm currently trying.