TargetedPatchingOptOut:“跨 NGen 图像边界内联的性能至关重要”?

发布于 2024-11-09 06:02:31 字数 225 浏览 0 评论 0原文

使用反射器浏览一些框架类,并注意到许多方法和属性具有以下属性,

[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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我的奇迹 2024-11-16 06:02:31

它告诉 NGen 即使在不同的程序集中也可以内联其所应用的方法。

例如:

  • String.Equals[TargetedPatchingOptOut]
  • 您编写了一个调用 String.Equals 的程序
  • 您运行 NGen 在此程序上以获得最大性能
  • NGen 将内联 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]
  • 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.

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.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文