none
Force Jit compile on assembly RRS feed

  • Question

  • I have CLR code that generates an assembly that I install into a database using the create assembly procedures.

    The code includes stored procedures and triggers.

    My separate applications, of course, call the stored procedures.

    My issue is that immediately after I install the library, the first time any of these triggers/procedures are called, it can take a long time for the event to occur.

    In a specific case (easily recreated on my end), if I hit a trigger with specific data in my record, something is occurring at the database level that is preventing me from doing a simple edit/save.  I think it's compiling the assembly.  It will work if I do an edit/save on another record, then go back to the first one.  Once that happens, the issue goes away until I delete and install the assembly, then it comes back for records that meet specific criteria.

    My conclusion is that it is taking so long for the JIT compiler, it's killing my post.

    So, question is:

    how can I force the jit compiler to process the assembly, either before or after installing the assembly to the database?

     

    Friday, August 20, 2010 4:42 PM

Answers

  • If the assembly sits in the GAC you could ngen it.

    • Marked as answer by SamAgain Thursday, August 26, 2010 6:43 AM
    Friday, August 20, 2010 7:31 PM
  • The system places the binary it generates in a system-folder (somewhere in c:\windows\microsoft.net if i remember correctly) and will detect next time the assembly is loaded by an application that there is a native binary available and will use that instead of the jitting the msil code. You should never have to look for or touch the native dll
    • Marked as answer by SamAgain Thursday, August 26, 2010 6:43 AM
    Saturday, August 21, 2010 3:12 PM
  • > My question for that is where does the output of ngen go?

    They go under c:\Windows\assembly\NativeImages_vFrameworkVersionNumber_32/64

    Manipulating this folder yourself is not a good idea.  ngen has the command-line options you need to query and correctly perform operations on the native images.

     

     

    • Marked as answer by SamAgain Thursday, August 26, 2010 6:43 AM
    Saturday, August 21, 2010 10:19 PM
  • An alternative way trigger JIT compilation on your assemblies is to do it during runtime (instead of using NGen as a preperation step).
    The basic idea revolves around using the PrepareMethod function available in RuntimeHelpers .

    The concept is explained in more depth here: http://blog.liranchen.com/2010/08/forcing-jit-compilation-during-runtime.html

    • Marked as answer by SamAgain Thursday, August 26, 2010 6:43 AM
    Tuesday, August 24, 2010 7:34 PM

All replies

  • If the assembly sits in the GAC you could ngen it.

    • Marked as answer by SamAgain Thursday, August 26, 2010 6:43 AM
    Friday, August 20, 2010 7:31 PM
  • My question for that is where does the output of ngen go?

    I tried doing that, but couldn't figure out where the 'output' goes.  If I could figure out the command line then I could add that to the the installation logic (to compile the dll before installing the assembly to the database).   I don't think it goes into the gac (because the dll is never call directly from a program, it is installed into the database as an assembly)


    Friday, August 20, 2010 9:42 PM
  • The system places the binary it generates in a system-folder (somewhere in c:\windows\microsoft.net if i remember correctly) and will detect next time the assembly is loaded by an application that there is a native binary available and will use that instead of the jitting the msil code. You should never have to look for or touch the native dll
    • Marked as answer by SamAgain Thursday, August 26, 2010 6:43 AM
    Saturday, August 21, 2010 3:12 PM
  • > My question for that is where does the output of ngen go?

    They go under c:\Windows\assembly\NativeImages_vFrameworkVersionNumber_32/64

    Manipulating this folder yourself is not a good idea.  ngen has the command-line options you need to query and correctly perform operations on the native images.

     

     

    • Marked as answer by SamAgain Thursday, August 26, 2010 6:43 AM
    Saturday, August 21, 2010 10:19 PM
  • I ran ngen on the dll.

     

    E:\DevCode\SME7.1\bin>ngen smeroutines.dll

    Microsoft (R) CLR Native Image Generator - Version 2.0.50727.3053

    Copyright (c) Microsoft Corporation.  All rights reserved.

    Installing assembly E:\DevCode\SME7.1\bin\smeroutines.dll

        Compiling assembly E:\DevCode\SME7.1\bin\smeroutines.dll ...

    SMERoutines, Version=7.1.1.10, Culture=neutral, PublicKeyToken=null

     

    E:\DevCode\SME7.1\bin>ngen install smeroutines.dll

    Microsoft (R) CLR Native Image Generator - Version 2.0.50727.3053

    Copyright (c) Microsoft Corporation.  All rights reserved.

    Installing assembly E:\DevCode\SME7.1\bin\smeroutines.dll

    All compilation targets are up to date.

     

    since isn't listed in c:\windows\assembly, and I can't even 'see' the native images directory, I did the install, then reinstalled the library to the database, and no change, so I don't thing ngen is the 'answer'.

    I even tried the compile/install after I installed to the database.

     

    Tuesday, August 24, 2010 3:35 PM
  • An alternative way trigger JIT compilation on your assemblies is to do it during runtime (instead of using NGen as a preperation step).
    The basic idea revolves around using the PrepareMethod function available in RuntimeHelpers .

    The concept is explained in more depth here: http://blog.liranchen.com/2010/08/forcing-jit-compilation-during-runtime.html

    • Marked as answer by SamAgain Thursday, August 26, 2010 6:43 AM
    Tuesday, August 24, 2010 7:34 PM