Have you ever used ngen.exe?

后端 未结 8 1114
感动是毒
感动是毒 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:09

    Yes, I've seen performance improvements. My measurements indicated that it did improve startup performance if I also put my assemblies into the GAC since my assemblies are all strong named. If your assemblies are strong named, NGen won't make any difference without using the GAC. The reason for this is that if you have strong named assemblies that are not in the GAC, then the .NET runtime validates that your strong named assembly hasn't been tampered with by loading the whole managed assembly from disk so it can validate it circumventing one of the major benefits of NGen.

    This wasn't a very good option for my application since we rely on common assemblies from our company (that are also strong named). The common assemblies are used by many products that use many different versions, putting them in the GAC meant that if one of our applications didn't say "use specific version" of one of the common assemblies it would load the GAC version regardless of what version was in its executing directory. We decided that the benefits of NGen weren't worth the risks.

提交回复
热议问题