Have you ever used ngen.exe?

后端 未结 8 1115
感动是毒
感动是毒 2021-01-31 07:40

Has anybody here ever used ngen? Where? why? Was there any performance improvement? when and where does it make sense to use it?

相关标签:
8条回答
  • 2021-01-31 08:32

    As an addition to Mehrdad Afshari's comment about JIT compilation. If serializing a class with many properties via the XmlSerializer and on a 64-bit system a SGEN, NGEN combo has a potentially huge (in our case gigabytes and minutes) effect.

    More info here: XmlSerializer startup HUGE performance loss on 64bit systems see Nick Martyshchenko's answer especially.

    0 讨论(0)
  • 2021-01-31 08:34

    i have used it but just for research purpose. use it ONLY if you are sure about the cpu architecture of your deployment environment (it wont change)

    but let me tell you JIT compilation is not too bad and if you have deployments across multiple cpu environments (for example a windows client application which is updated often) THEN DO NOT USE NGEN. thats coz a valid ngen cache depends upon many attributes. if one of these fail, your assembly falls back to jit again

    JIT is a clear winner in such cases, as it optimizes code on the fly based on the cpu architecture its running on. (for eg it can detect if there are more then 1 cpu)

    and clr is getting better with every release, so in short stick with JIT unless you are dead sure of your deployment environment - even then your performance gains would hardly justify using ngen.exe (probably gains would be in few hundred ms) - imho - its not worth the efforts

    also check this real nice link on this topic - JIT Compilation and Performance - To NGen or Not to NGen?

    0 讨论(0)
提交回复
热议问题