none
Why the JIT compiler not compile the code for one machine only once? RRS feed

  • Question

  • After rebooting, the .NET application starts slow again. 
    • Moved by Peter RitchieModerator Thursday, October 9, 2008 4:27 PM Question not specific to C# (Moved from Visual C# Language to Common Language Runtime)
    Wednesday, October 8, 2008 4:36 AM

Answers

  • No, the compiled code is stored on the harddrive.  The JIT only compiles code that it uses, so your entire assembly won't get compiled.  But, two invocations of the sample application in the same way should have all used code compiled on the second run.

    What Windows also does it cache in memory data that it has already loaded from disk (more so with Windows XP SP3).  So, running any application twice in close succession will be quicker on the second launch.  If you reboot, the Windows disk cache will be lost and it will have to reload it--an already JITted .NET application loaded for a third time will now load slower than the second...

    See http://msdn.microsoft.com/en-us/library/ht8ecch6(VS.71).aspx for more details on JIT.
    http://www.peterRitchie.com/blog
    • Marked as answer by followait Saturday, October 11, 2008 1:07 AM
    Friday, October 10, 2008 2:32 PM
    Moderator

All replies

  • Because it wouldn't be a JIT compiler if it did. Let's say it does only compile once. How will it know if the source changed? Now it needs to be version control, and a compiler. Where does it store the compiled code? Disk manager too.


    Ron Whittle
    Wednesday, October 8, 2008 4:56 AM
  • you can prejit code using the ngen tool, see msdn on how to use it and what its limitations are.
    Wednesday, October 8, 2008 6:02 AM
  • I see, negen got some limitations, I'm just thinking about this.
    When the application runs after rebooting, it seems that the code need to be compiled again,
    though the machine code it generates is just the same as the last time it generates.
    So why not put it in some cache?
    And there could be a mechanism that detects if the cached machine code need to be updated.
    The cache could be transparent, and there will be no problem that incurred by ngen.
    • Edited by followait Wednesday, October 8, 2008 10:42 AM patch
    Wednesday, October 8, 2008 10:21 AM
  • Are you confusing JITting and disk caching?  The Jitter only JITs code once.   If you launch the same application the same way and it's slower than before, you're likely looking at disk caching, not JITing...
    http://www.peterRitchie.com/blog
    Thursday, October 9, 2008 4:27 PM
    Moderator
  • Yes, all about cache.

    In my experience (the speed to start the appliction), it seems that the compiled code is cached after the first time it runs, but after rebooting the machine, the cached code seems lost, and it need to be recompiled again. Is this true?
    Friday, October 10, 2008 2:25 PM
  • No, the compiled code is stored on the harddrive.  The JIT only compiles code that it uses, so your entire assembly won't get compiled.  But, two invocations of the sample application in the same way should have all used code compiled on the second run.

    What Windows also does it cache in memory data that it has already loaded from disk (more so with Windows XP SP3).  So, running any application twice in close succession will be quicker on the second launch.  If you reboot, the Windows disk cache will be lost and it will have to reload it--an already JITted .NET application loaded for a third time will now load slower than the second...

    See http://msdn.microsoft.com/en-us/library/ht8ecch6(VS.71).aspx for more details on JIT.
    http://www.peterRitchie.com/blog
    • Marked as answer by followait Saturday, October 11, 2008 1:07 AM
    Friday, October 10, 2008 2:32 PM
    Moderator
  •  Thanks, it's fine.
    Saturday, October 11, 2008 1:07 AM