问题描述
浏览了一些使用反射器的框架类,注意到一些方法和属性具有以下属性
Been going through some framework classes using reflector and noticed a number of the methods and properties have the following attribute
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
我很确定我在其他地方也看到过上述评论,但从未跟进.
I'm pretty sure I have also seen the above comment somewhere else and never followed it up.
谁能告诉我这在 C# 和任何其他上下文中意味着什么?
Could someone please tell me what this means in the C# and any other context?
推荐答案
它告诉 NGen 即使在不同的程序集中也可以内联它所应用的方法.
It tells NGen that it is OK to inline the method it's applied to even in a different assembly.
例如:
String.Equals
有[TargetedPatchingOptOut]
- 您编写了一个调用
String.Equals
的程序 - 您运行 NGen这个程序以获得最佳性能
- NGen 将内联
String.Equals
调用,将方法调用指令替换为方法中的实际代码.
方法调用(稍微)昂贵,因此对于经常调用的方法来说,这是一种性能提升.
String.Equals
has[TargetedPatchingOptOut]
- You write a program that calls
String.Equals
- You run NGen on this program for maximum performance
- NGen will inline the
String.Equals
call, replacing the method call instruction with the actual code in the method.
Method calls are (slightly) expensive, so this is a performance boost for frequently-called methods.
但是,如果 Microsoft 在 String.Equals
中发现安全漏洞,他们不能只更新 mscorlib.dll
,因为这不会影响您刚刚 NGen 的程序集'd.(因为它具有未引用 String.Equals
的原始机器代码).
我假设如果这真的发生了,安全更新会清除 NGen 存储.
However, if Microsoft finds a security hole in String.Equals
, they cannot just update mscorlib.dll
, because that won't affect the assembly that you just NGen'd. (Since it has raw machine code without referencing String.Equals
).
I assume that if that were to actually happen, the security update would clear the NGen store.
请注意,此属性仅在 .NET Framework 程序集中有用.你自己不需要它.您可以在此处找到更多信息:https://stackoverflow.com/a/14982340/631802
Note that this attribute is only useful in the .NET Framework assemblies. You don't need it in your own. You can find more information about that here: https://stackoverflow.com/a/14982340/631802
这篇关于TargetedPatchingOptOut:“性能对跨 NGen 图像边界内联至关重要"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!