I'm using C#.NET for a web application. I've read that JIT compilation happens at run-time, which means(correct me if I'm wrong) that the compilation will happen when the request hits IIS.
Another compilation happens using csc.exe
during the build phase of the solution using MSBuild
to convert high-level code to CIL.
If there was no JIT and we wanted to use AOT, where would AOT fit in all this?
My question is at what point in the entire phase from building code to the first request, AOT compilation happens? (The platform/framework does not matter)
The Angular ahead-of-time (AOT) compiler converts your Angular HTML and TypeScript code into efficient JavaScript code during the build phase before the browser downloads and runs that code. Compiling your application during the build process provides a faster rendering in the browser.
What Is Ahead of Time Compilation? AOT compilation is one way of improving the performance of Java programs and in particular the startup time of the JVM. The JVM executes Java bytecode and compiles frequently executed code to native code. This is called Just-in-Time (JIT) Compilation.
JIT downloads the compiler and compiles code exactly before Displaying in the browser. AOT has already complied with the code while building your application, so it doesn't have to compile at runtime. Loading in JIT is slower than the AOT because it needs to compile your application at runtime.
In computer science, ahead-of-time compilation (AOT compilation) is the act of compiling an (often) higher-level programming language into an (often) lower-level language before execution of a program, usually at build-time, to reduce the amount of work needed to be performed at run time.
After a lot of Googling and research, I found out that my basic understanding of the compilers was wrong.
A compiler is a program that converts a program in language X to a program in language Y. The language Y can be anything(native machine code, intermediate code/bytecode, some other language Z, or the same language itself).
A compiler is not necessarily a program that converts a program in language X to m-code.
For example, a compilation happens from high-level C# code to CIL using a compiler csc.exe. (how could I miss that? duh!)
Also, the time in Ahead-Of-Time and Just-In-Time compilers refers to the runtime. So, in Ahead-Of-Time compiler, the compilation happens before the program is run, usually added as a build step. While in Just-In-Time compiler, the compilation keeps happening while the program is being run.
To put it in C#.NET perspective and to answer my question, the CIL is generated by MSBuild using csc.exe without any consideration whether the CLR uses JIT or AOT compiler. It is at the time of running the program that JIT or AOT compiler comes into action. AOT compiler compiles entire assemblies(in CIL, or language X) into native machine code(language Y) before the program is run. JIT compiler compiles individual methods and classes(in CIL, or language X) into native machine code(language Y) when the methods are called.
CLR provides JIT compiler by default but it also supports AOT compilation using Native Image Generator(Ngen.exe).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With