The Just In Time Compiler, a new feature in HALCON 12

The Just In Time Compiler (JIT), is designed to speed up processes without the necessity to use a compiled language such as C, C++ or C#. Thus, HDevEngine executed code can get nearly as fast as a compiled one.

The speed enhancement is possible because procedures for the architecture you are currently working on are compiled in the background, without any need for user interaction. This has the biggest effect when the procedure contains a considerable amount of program line switching (e.g. loops).

The JIT Compiler is turned off by default. The image and the code below show how to switch it on in HDevelop:

HDevelop_JIT_SwitchOn_Circle

C++:

HDevEngine my_engine;
my_engine.SetEngineAttribute(“execute_procedures_jit_compiled”,”true”);

C#:
Engine = new HDevEngine();
Engine.SetEngineAttribute(“execute_procedures_jit_compiled”,”true”);

HDevelop automatically compiles the procedures before the first execution. HDevEngine compiles the procedure at the first call. If it is preferable to start with an already compiled procedure the following code helps:

C++:
HDevProgram my_program(program_path.c_str());
HDevProcedure proc_fib(my_program,”fib”);

proc_fib.CompileUsedProcedures();

C#:
Proc = new HDevProcedure(Program, name);

Proc.CompileUsedProcedures();

If the JIT compiled procedure contains a lot of program line switching, a huge speed improvement is possible. To get a first impression the HDevelop example program test_jit_speedup.hdev can be executed.

For example the following calculation of the Fibonacci numbers speeds up by a factor of twelve on our system:

if (N <= 0)
Fib := 0
elseif (N == 1 or N == 2)
Fib := 1
else
fibonacci (N – 1, A)
fibonacci (N – 2, B)
Fib := A + B
endif

While using the JIT Compiler it’s important to pay attention to the limitations mentioned in the HDevelop Users Guide chapter 5.8 Just-In-Time Compilation.

JITtweet

We hope this article helps you make the most of this new feature!! If you have any questions please contact our support team.