TargetedPatchingOptOut:“跨 NGen 图像边界内联的性能至关重要”?
使用反射器浏览一些框架类,并注意到许多方法和属性具有以下属性,
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
我很确定我也在其他地方看到了上述评论,但从未跟进过。
有人可以告诉我这在 C# 和任何其他上下文中意味着什么吗?
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.
Could someone please tell me what this means in the C# and any other context?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它告诉 NGen 即使在不同的程序集中也可以内联其所应用的方法。
例如:
String.Equals
有[TargetedPatchingOptOut]
String.Equals
的程序String .Equals
调用,将方法调用指令替换为方法中的实际代码。方法调用(稍微)昂贵,因此这对于频繁调用的方法来说是性能提升。
但是,如果 Microsoft 在
String.Equals
中发现安全漏洞,他们就不能只更新mscorlib.dll
,因为这不会影响您刚刚 NGen 生成的程序集。 (因为它具有原始机器代码,没有引用String.Equals
)。我认为如果这种情况真的发生,安全更新将清除 NGen 存储。
请注意,此属性仅在 .NET Framework 程序集中有用。你自己不需要它。您可以在此处找到更多相关信息:https://stackoverflow.com/a/14982340/631802
It tells NGen that it is OK to inline the method it's applied to even in a different assembly.
For example:
String.Equals
has[TargetedPatchingOptOut]
String.Equals
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.
However, if Microsoft finds a security hole in
String.Equals
, they cannot just updatemscorlib.dll
, because that won't affect the assembly that you just NGen'd. (Since it has raw machine code without referencingString.Equals
).I assume that if that were to actually happen, the security update would clear the NGen store.
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