Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Doubt in NGEN and CLR

Doubt in NGEN and CLR

Scheduled Pinned Locked Moved .NET (Core and Framework)
c++csharpdotnetperformancequestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    He is Cool
    wrote on last edited by
    #1

    Hi, I need some basic low level details of what happens when you ngen a .NET assembly. Lets take a c++ code which when compiled creates a binary executable. On executing this binary, the OS allocates memory for the process and executes it. No concept of runtime or CLR here. Everything is present in the binary. I read the MSDN and understand that .NGEN creates a native image of the code and avoids JIT compilation while execution by the CLR. Hence, at the end, I understand that the ngen creates binary code for specific processor. If the native code (binary) is ready then why cant the OS take care of executing it and why the .NET runtime has to do the execution? What does the CLR do then for a ngended assembly ? I seem to get confused with this concept.Please clarify. Thanks, Mani

    L 1 Reply Last reply
    0
    • H He is Cool

      Hi, I need some basic low level details of what happens when you ngen a .NET assembly. Lets take a c++ code which when compiled creates a binary executable. On executing this binary, the OS allocates memory for the process and executes it. No concept of runtime or CLR here. Everything is present in the binary. I read the MSDN and understand that .NGEN creates a native image of the code and avoids JIT compilation while execution by the CLR. Hence, at the end, I understand that the ngen creates binary code for specific processor. If the native code (binary) is ready then why cant the OS take care of executing it and why the .NET runtime has to do the execution? What does the CLR do then for a ngended assembly ? I seem to get confused with this concept.Please clarify. Thanks, Mani

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      When NGen compiles your IL into a native assembly is still uses the CLR and the .NET framework class libraries. Also there would be a problem with updates to the .NET framework. For example if there was a security hole in the console.writeline method and you installed a patch for it then all the apps that use that method would not be updated and would require re-Ngening. Here are some pros and cons to NGening. PROS: Improved application startup time: Since there is no JIT compilation. Reducing the apps working set: Best if the app is going to be loaded into mutliple AppDomain or processes at the same time. Although the working set will still be less if not being used in multiple appdomains/processes. CONS: NGen files can get out of sync: updates to the hardware or .NET Framework will cause this. Load-time performance hit: NGen files have the memory address references statically calculated. If for some reason it cannot be loaded at its preferred base address then it will require rebasing (Windows will have to relocate the file and fix up memory address references.) Slower runtime performance: Ngen cannot make as many assumptions about the hardware and OS as the JIT can. The JIT can perform many more optimizations than NGen

      █▒▒▒▒▒██▒█▒██ █▒█████▒▒▒▒▒█ █▒██████▒█▒██ █▒█████▒▒▒▒▒█ █▒▒▒▒▒██▒█▒██

      R 1 Reply Last reply
      0
      • L Lost User

        When NGen compiles your IL into a native assembly is still uses the CLR and the .NET framework class libraries. Also there would be a problem with updates to the .NET framework. For example if there was a security hole in the console.writeline method and you installed a patch for it then all the apps that use that method would not be updated and would require re-Ngening. Here are some pros and cons to NGening. PROS: Improved application startup time: Since there is no JIT compilation. Reducing the apps working set: Best if the app is going to be loaded into mutliple AppDomain or processes at the same time. Although the working set will still be less if not being used in multiple appdomains/processes. CONS: NGen files can get out of sync: updates to the hardware or .NET Framework will cause this. Load-time performance hit: NGen files have the memory address references statically calculated. If for some reason it cannot be loaded at its preferred base address then it will require rebasing (Windows will have to relocate the file and fix up memory address references.) Slower runtime performance: Ngen cannot make as many assumptions about the hardware and OS as the JIT can. The JIT can perform many more optimizations than NGen

        █▒▒▒▒▒██▒█▒██ █▒█████▒▒▒▒▒█ █▒██████▒█▒██ █▒█████▒▒▒▒▒█ █▒▒▒▒▒██▒█▒██

        R Offline
        R Offline
        Robert Rohde
        wrote on last edited by
        #3

        Hi,

        Captain See SharpSlower runtime performance: Ngen cannot make as many assumptions about the hardware and OS as the JIT can. The JIT can perform many more optimizations than NGen

        Is this always true, also when NGening the assemblies directly on the target machine? Robert

        H L 2 Replies Last reply
        0
        • R Robert Rohde

          Hi,

          Captain See SharpSlower runtime performance: Ngen cannot make as many assumptions about the hardware and OS as the JIT can. The JIT can perform many more optimizations than NGen

          Is this always true, also when NGening the assemblies directly on the target machine? Robert

          H Offline
          H Offline
          He is Cool
          wrote on last edited by
          #4

          So, if I have a stand alone .NET application in a system, Ngening those .NET assemblies is recommended or not. Please clarify.

          L 1 Reply Last reply
          0
          • R Robert Rohde

            Hi,

            Captain See SharpSlower runtime performance: Ngen cannot make as many assumptions about the hardware and OS as the JIT can. The JIT can perform many more optimizations than NGen

            Is this always true, also when NGening the assemblies directly on the target machine? Robert

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Robert Rohde wrote:

            Is this always true, also when NGening the assemblies directly on the target machine?

            Yes. NGened asemblies run about %5 slower than a JITed assembly.

            █▒▒▒▒▒██▒█▒██ █▒█████▒▒▒▒▒█ █▒██████▒█▒██ █▒█████▒▒▒▒▒█ █▒▒▒▒▒██▒█▒██

            1 Reply Last reply
            0
            • H He is Cool

              So, if I have a stand alone .NET application in a system, Ngening those .NET assemblies is recommended or not. Please clarify.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              He is Cool wrote:

              So, if I have a stand alone .NET application in a system, Ngening those .NET assemblies is recommended or not.

              You would definitly not NGen an assembly if it is a server application as the performace hit would only be on the first request. In general you should not NGen an assembly unless you have a very good reason to and in most cases there is no reason to. One reason to NGen an assembly would be to reduce the working set and improve startup performance but usually the overall runtime performance of your app would not be as good as if it were JITed.

              █▒▒▒▒▒██▒█▒██ █▒█████▒▒▒▒▒█ █▒██████▒█▒██ █▒█████▒▒▒▒▒█ █▒▒▒▒▒██▒█▒██

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups