www.espertech.comDocumentation

Chapter 22. Code Generation

22.1. Introduction
22.2. Usage Notes
22.2.1. Criteria
22.2.2. Fallback
22.2.3. Logging
22.2.4. Debugging Generated Code

Esper may generate and compile code upon statement creation using the Janino compiler. Code generation is a technique that blends state-of-the-art from modern compilers and MPP databases.

Code generation can significantly speed up processing as it eliminates many virtual calls and especially megamorphic calls (a callsite with 3 or more possible implementations is megamorphic) as well as casts and branching. Code generation allows the runtime to optimize the generated code and allows the hardware to execute faster.

Tip

The engine implements the best architecture for performance engineering in data processing by performing code generation. Not all workloads can benefit from code generation to the same degree.

Code generation is enabled by default and can be disabled entirely. Please refer to Section 15.4.12, “Engine Settings related to Code Generation and Compilation” for configuration options.

For example, consider the expression a + b (field a plus field b). Upon creating a statement the engine performs these steps:

  1. Analyzes the expression and determines where fields a and b come from (for example event type or variable) and the field type (for example string or integer).

  2. Verifies that the addition arithmetic operation can indeed be applied to the two fields. It verifies that both fields are indeed numeric and can thus be added.

Without code generation, in order to evaluate the expression a + b the engine needs to make at least 3 virtual calls: One to obtain the value of field a, one to obtain the value of field b and one to perform the + plus-operation.

With code generation the engine can reduce the number of virtual calls. In the best case the number of virtual calls to evaluate the a + b expression is one (for the invocation of the generated code itself).

All code generation takes place at time of EPL statement creation. There is no code generation at runtime.

You can log generated classes at INFO log level by setting the configuration flag for code logging as described in Section 15.4.16.5, “Code Generation Logging”.

As an alternative you can configure your log provider configuration file by setting DEBUG level for class com.espertech.esper.codegen.compile.CodegenCompilerJanino (provider class may change between versions).