Compilation, JIT, preprocessor
A compiler is a computer program (or a set of programs) that transforms source code written in a programming language (the source language) into another computer language (the target language), with the latter often having a binary form known as object code. The most common reason for converting source code is to create an executable program.
The name "compiler" is primarily used for programs that translate source code from a high-level programming language to a lower level language (e.g., assembly language or machine code). If the compiled program can run on a computer whose CPU or operating system is different from the one on which the compiler runs, the compiler is known as a cross-compiler. More generally, compilers are a specific type of translator.
- Here you have specific optimisation (SIMD, see below) to do the software CPU specific to improve the performance using the full instruction set
- Generic optimisation as unroll loop, ...
- This mode don't take care of compilation time, mean it can do more advanced optimisation than JIT
In computing, just-in-time (JIT) compilation, also known as dynamic translation, is compilation done during execution of a program – at run time – rather than prior to execution. Most often this consists of translation to machine code, which is then executed directly, but can also refer to translation to another format.
What is the change against the compilation?
- Use all the instruction set of the cpu, allow usage of SIMD (MMX, SSE, AVX, ...) to improve the performance without change the code (as multi-thread programming)
- Take care of one time loaded variable:
var toto=config[Toto] if(toto==X) do something else do another thing
The jit will detect that's and do:
if(true)//the condition is always true/false do something else do another thing
And will optimise as:
Mean: Less register used (high speed memory block of 32Bits if the cpu is 32Bits), deterministic behaviour and more optimisation possibility, lighter context and less context change
- Less CPU cache (L1, L2) flush
- Better usage of the branch predictor:
In computer architecture, a branch predictor is a digital circuit that tries to guess which way a branch (e.g. an if-then-else structure) will go before this is known for sure. The purpose of the branch predictor is to improve the flow in the instruction pipeline. Branch predictors play a critical role in achieving high effective performance in many modern pipelined microprocessor architectures such as x86.
- In some case it use opcode (Java, ...), that's allow do the generic optimisation before the JIT part and offload part of the work: The JIT is only hear to compil into assembly and do the platform/assembly specific optimisation
In computer science, a preprocessor is a program that processes its input data to produce output that is used as input to another program. The output is said to be a preprocessed form of the input data, which is often used by some subsequent programs like compilers. The amount and kind of processing done depends on the nature of the preprocessor; some preprocessors are only capable of performing relatively simple textual substitutions and macro expansions, while others have the power of full-fledged programming languages.
- The Preprocessor into C or C++ and achieve most of JIT part by putting it at compilation time, by this config can't be changed (you need recompil it).
- This allow drop some code to have less size (usefull for embedded), disable code with potential security problem