Print
Optimizers
Applicability of Optimizers

Note: This page is only of relevance to using compiled MVEL expressions. Optimizers are not used when executing an expression in purely interpreted mode such as with: MVEL.eval()

Since MVEL is a dynamic language using a dynamic runtime, it is through necessity that scripts access fields and methods of objects via reflection. As this has serious performance implications, MVEL is equipped with optimizers which are designed to either minimize or remove the overhead of reflection calls.

By default, MVEL has two default optimizers: the Reflective optimizer, and the ASM (Bytecode) optimizer.

The Reflective Optimizer

The reflective optimizer is also referred to as the SAFE_REFLECTIVE optimizer in parts of the API, as an indication that it's use is completely safe, has no impact on class loading and is guaranteed to be compatible with all language constructs. The ASM optimizer may in some cases fall back on this optimizer for certain operations that cannot be compiled to bytecode for various reasons.

The reflective optimizer performs it's optimization by producing a Fast Reflection Evaluation Tree which negates the need for field and method lookups at runtime by caching reflection targets within a normalized evaluation tree.

This optimizer can be made default by configuring MVELs OptimizerFactory:

OptimizerFactory.setDefaultOptimizer("reflective")

The ASM (Bytecode) Optimizer

The ASM bytecode optimizer is enabled by default in MVEL. It uses an inlined version of the ASM 3.0 Bytecode Manipulation library to produce compiled reflection accessor stubs which are used in place of reflection calls.

The optimizer is made default by using the following API call:

OptimizerFactory.setDefaultOptimizer("ASM");
Powered by Atlassian Confluence