Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many times is .NET compiling IL

I'm reading second book and it's still not obvious.

My question is: How many times IL language is compiled: a) Every time from the beginning durning the execution of application. b) Once, after first execution.

like image 633
user1798039 Avatar asked Jan 30 '26 03:01

user1798039


1 Answers

It's a) -Every time the program is executed. As bits of the assemblies are executed, the JITter compiles and caches them in memory. So each bit is only compiled once before it's run, then run natively each time after that. However, these compiled bits are only stored in memory and are thrown away after the program terminates.

If you want to, you can you can use ngen to create and cache compiled images, in which case the answer becomes C) - Once, before execution.

An important special-case clarification ( from svick ). Note that on Windows 8, an assembly that targets .Net 4.5 or later, and is either installed into the GAC or comes from the Windows Store is a candidate for automatic native image generation. These native images are created by the scheduled NGen Task based on usage.

like image 134
Philip Rieck Avatar answered Feb 01 '26 21:02

Philip Rieck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!