简体   繁体   English

.NET 核心:MethodImplOptions.AggressiveOptimization 到底是做什么的?

[英].NET Core: What does MethodImplOptions.AggressiveOptimization exactly do?

What does MethodImplOptions.AggressiveOptimization exactly do? MethodImplOptions.AggressiveOptimization究竟做了什么? Microsoft's documentation doesn't not tell me much. 微软的文档并没有告诉我太多。 In which cases can it be useful?它在哪些情况下有用?

I would look for more details info (if that's what's you are looking for) not in the documentation but on .net core github or in release notes .我会在文档中而不是在.net 核心 github发行说明中寻找更多详细信息(如果这是您正在寻找的)。

Let's start by looking at the latter.让我们从后者开始。 For .net core 3.0 we can find the following entry:对于 .net 内核 3.0,我们可以找到以下条目:

The fully optimizing JIT produces higher-quality (or more optimized) code more slowly.完全优化的 JIT 更慢地生成更高质量(或更优化)的代码。 For methods where Quick JIT would not be used (for example, if the method is attributed with MethodImplOptions.AggressiveOptimization), the fully optimizing JIT is used.对于不使用 Quick JIT 的方法(例如,如果该方法具有 MethodImplOptions.AggressiveOptimization 属性),则使用完全优化的 JIT。

So for one, we know that if a method is marked with such attribute, it should be JITed with fully optimizing JIT, which might produce better, more optimized code - but would take more time to compile.因此,首先,我们知道,如果一个方法被标记了这样的属性,它应该使用完全优化的 JIT 进行 JIT,这可能会产生更好、更优化的代码 - 但会花费更多时间来编译。

Now let's focus on github and see what we can find there.现在让我们关注 github,看看我们能找到什么。

The discussion about this is done in this ticket , and it gives a bit more details into the topic.有关此问题的讨论已在此票证中完成,并提供了有关该主题的更多详细信息。

The flag could be used in a MethodImplAttribute to indicate that the method contains hot code:该标志可用于 MethodImplAttribute 以指示该方法包含热代码:

  • For tiering, it could cause tier 1 JIT to be used right away for the method[...]对于分层,它可能会导致第 1 层 JIT 立即用于方法 [...]
  • It could allow the JIT to spend more JIT time to generate better code, such as inlining more aggressively into the function它可以让 JIT 花费更多的 JIT 时间来生成更好的代码,例如更积极地内联到 function

From this we can get an answer to, in which cases it could be used but also what it is doing underneath.从中我们可以得到答案,在哪些情况下可以使用它,以及它在下面做什么。

In cases we deal with hot path code - this attribute is useful to JIT it to produce faster, more optimized code instead of doing tiered compilation.在我们处理热路径代码的情况下 - 此属性对于 JIT 很有用,可以生成更快、更优化的代码,而不是进行分层编译。 Using more time at the beginning saves time later if runtime detects that it's, in fact, on the hot path.如果运行时检测到它实际上在热路径上,则在开始时使用更多时间可以节省时间。

There's also an interesting discussion about other usages of this flag which you can read.还有一个关于这个标志的其他用法的有趣讨论,你可以阅读。

But the ultimate truth (I hope) and commits are linked to this discussion so we can look at them.但是最终的真相(我希望)和提交与这个讨论有关,所以我们可以看看它们。 And from those commits and commit messages we can get that this is in fact what's happening with tiered compilation and JIT (at least this is what I can see).从这些提交和提交消息中,我们可以了解到这实际上是分层编译和 JIT 正在发生的事情(至少这是我能看到的)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM