Difference between Ahead-of-time and Just-In-Time Compilation

While reading about templates for ASP.NET I saw that one had support for AOT (Ahead of Time) and the other did not speak anything.

I've been researching on the subject and I couldn't quite understand the difference and definition Ahead of time and Just in Time in the compilation issue because I didn't understand the process perfectly.

How do the two mentioned above really work? Could you give me an example?

Author: Maniero, 2019-01-17

1 answers

The AOT compiler is the most traditional where you develop, in it you invoke the compiler and it does the whole process culminating in the executable that can be called on time or transported to another location. Usually it doesn't have to be that fast and can do more extreme optimizations.

The JIT compiler is invoked at runtime, so on each call of the executable there is a build process. It is common that you have a previous build process that already it ensures that some things are correct and maintains an easier format to manipulate. As it will run every time it is important that the process is fast. So it is common that it is not good at doing optimizations, except for the most sophisticated ones that detect that something is executed many times (hot path ) and compensates for doing a larger optimization process, and then it can even give a better result because it already has more information about the execution environment and current context (it is called tiering ). It can be seen more in What is a JITter?.

In a way we can say that interpreters are JITters, although the term is not usually used, it seems to me even more appropriate than "interpreter", at least in most current implementations.

The best known JITters are from Java and C#, both have a previous build process before. If we consider the interpretation we can talk about almost all implementations of the JavaScript )PHP will have). Other languages that are often considered interpreted may have a more classical JITter process. The most well-known AOTs are from C and C++, as well as Delphi, Go, D, Rust. But note that all these languages can and usually have both forms. One does not prevent the other unless the language has specified differently for some reason, but this does not usually happen.

When it is common to use the JITter and the technology allows the AOT can give a gain in the load this can be very important where you have a lot of calls to the executable and need to respond fast.

In the case of templates can only refer to the fact that the template turns a code that mounts the strings directly without having to interpret the template code. I wouldn't exactly call it JIT or AOT compilation in that case, despite being something like that, I would say this is just a code generation.

 3
Author: Maniero, 2020-08-24 18:25:07