0

Possible Duplicate:
Is CLR loaded and initialized everytime,when a new managed application is loaded ?

When you startup some .NET app, does the OS have to load the .NET runtime each time too or is that already running?

The app has to be JIT'ed before it can be executed each time by the runtime right?

Doesn't that slow things down? How does this work?

Community
  • 1
  • 1
Tony The Lion
  • 61,704
  • 67
  • 242
  • 415
  • 1
    Similar question: [Is CLR loaded and initialized everytime,when a new managed application is loaded ?](http://stackoverflow.com/questions/3245791/is-clr-loaded-and-initialized-everytime-when-a-new-managed-application-is-loaded) – Devendra D. Chavan Mar 29 '11 at 08:53

2 Answers2

4

Yes, the .NET runtime is per-process

Re JIT; it is per-method, so it doesn't all need to be JITted; and it is very fast. You can use NGEN (or AOT on mono) to avoid this slight delay. But JIT delay is rarely a huge problem.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • +1 Good point about the fact that it doesn't *all* need to be JIT'd. :) But idk about the "very fast" part... I think the OP was referring to the entire set of problems (loading, compiling, etc.), and cold .NET startup is *very* slow... it's pretty much the opposite of what I'd call "very fast". – user541686 Mar 29 '11 at 09:02
  • @Mehrdad, the startup and memory consumption of a managed application is different in Win7. – Devendra D. Chavan Mar 29 '11 at 09:11
  • @Devendra: I was actually referring to Windows 7... ;) it's even worse in the other versions, true, but it's still pretty bad in Windows 7. (By the way, I was saying *nothing* about memory consumption, just about startup speed.) – user541686 Mar 29 '11 at 09:15
  • @Mehrdad, isn't the startup speed dependent on the dependent on the amount of initial memory allocated (assuming no i/o operations or processing at startup)? – Devendra D. Chavan Mar 29 '11 at 09:24
  • @Devendra: Well but the entire reason it's slow is the disk I/O -- my hard disk gets pretty busy when a .NET app starts up for the first time after a cold boot. :( – user541686 Apr 06 '11 at 00:18
2
  1. Yes, the .NET runtime has to be loaded into every new process, because every new process needs threads, a heap, new app domain(s), etc.

  2. Yes, unless it's already compiled by ngen, in which case it's already JIT'd.

  3. Yes, it slows down startup quite noticeably. Just run a Windows Forms program after boot and you'll see a typical ~10-20 second delay on a hard disk. Once things get going, though, the performance is acceptable, although the transitions between managed and unmanaged code can sometimes be strong bottlenecks, depending on how heavily your code makes platform invoke calls.

user541686
  • 205,094
  • 128
  • 528
  • 886
  • 2
    The .NET runtime is always mapped into the process, but it may already be loaded. – Brian Rasmussen Mar 29 '11 at 08:56
  • @Brian: I didn't use the term "load" to mean "physically read from the disk", but rather that it would need to be mapped, initialized with a new heap and app domain, threads and such, etc.; i.e. it can't re-use any resources that already exist in a different process. Thanks for the clarification though. – user541686 Mar 29 '11 at 08:58
  • I don't agree with 2 because JIT works per method. – Andrey Mar 29 '11 at 08:59
  • @Andrey: Not sure what you mean? The methods have to be JIT'd each time the app is loaded, don't they? – user541686 Mar 29 '11 at 09:00
  • @Mehrdad I meant that not all methods are JITed at start up. Methods are JITed lazily, when needed. – Andrey Mar 29 '11 at 09:34
  • @Andrey: Okay, but they're still JIT'd each time, which is what I think the OP asked... – user541686 Mar 29 '11 at 14:07