0

I'm having confusion between usual compilation and JIT. And would like to ask with an example.

Let's say we have a WinForms or WPF GUI application running. Does JIT happen when I click on the button? In other words when an event happens in a running .Net application, does the compilation take place at that moment(when we click on the button) or all JIT already happens during the execution(when we clicked on the exe file to start the program)?

user1999
  • 199
  • 8
  • Does this answer your question? [Does jitting happen every time a .NET application runs?](https://stackoverflow.com/questions/27131996/does-jitting-happen-every-time-a-net-application-runs) – Martheen Apr 13 '21 at 07:54
  • No but Im not asking about JIT for each time app runs, Im asking about events after the file already executed and running. They are different questions. – user1999 Apr 13 '21 at 07:57
  • events are just code, there's no special treatment for them. – Martheen Apr 13 '21 at 08:01
  • You didnt get it. I mean when you click on exe file normally programs compile all Im not asking that part. – user1999 Apr 13 '21 at 10:57

1 Answers1

1

By default, JIT happens ... "just in time", i.e. the first time a method is accessed, so: it might happen the first time you click the button, but not the next (unless you end up going down different code paths and other methods need JIT). Event handlers are methods, and there is no difference in how the JIT works for them. There is also tiered JIT in recent .NET versions, which means the first JIT is fast but not obsessively optimized, but if the runtime detects that it is being used a lot, it might spend some extra time improving the performance.

Depending on the build mechanism, it is also possible to do the JIT at build ahead of time ("AOT"); which might also involve profile guided optimizations ("PGO") if you have already captured usage data that might help it generate optimal code.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900