CLR 编译器优化示例

发布于 2024-09-19 05:04:56 字数 112 浏览 1 评论 0原文

几个月后我将做一个关于 .Net 性能和优化的演示,我想提供一些不必要的优化示例,无论如何这些事情都会由编译器完成。

我在哪里可以找到一些关于编译器实际上能够在代码之前和之后进行哪些优化的解释?

I'm doing a presentation in few months about .Net performance and optimization, I wanted to provide some samples of unnecessary optimization, things that will be done by the compiler anyways.

where can I find some explanation on what optimizations the compiler is actually capable of maybe some before and after code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

月棠 2024-09-26 05:04:56

查看这些链接

  1. C# 编译器优化< /a>
  2. 编译器优化
  3. msdn

另请查看这本有关 MSIL 的书
1. 微软中间语言:C# 和 VB.NET 的比较 / Niranjan Kumar

check out these links

  1. C# Compiler Optimizations
  2. compiler optimization
  3. msdn

Also checkout this book on MSIL
1. Microsoft Intermediate Language: Comparison Between C# and VB.NET / Niranjan Kumar

窝囊感情。 2024-09-26 05:04:56

我认为比“编译器无论如何都会完成的事情”的示例更好的是编译器执行开发人员假设的“优化”的场景示例 会带来性能提升,但事实上却不会。

例如,有时开发人员会认为在本地缓存一个值会提高性能,而实际上,堆栈上少一个值所节省的成本超过了可内联的字段访问的微小成本。

或者开发人员可能会认为“强制内联”方法调用(本质上是通过删除调用本身并用复制/粘贴的代码替换)是值得的,而实际上按原样保留方法调用将导致其内联仅当有意义时(当内联的好处超过代码大小的增长时)才由编译器执行。

当然,这只是一个一般想法。我没有可以指出的具体代码示例;但如果你寻找的话也许你可以找到一些。

What I think would be even better than examples of "things that will be done by the compiler anyways" would be examples of scenarios where the compiler doesn't perform "optimizations" that the developer assumes will yield a performance improvement but which, in fact, won't.

For example sometimes a developer will assume that caching a value locally will improve performance, when actually the savings of having one less value on the stack outweighs the miniscule cost of a field access that can be inlined.

Or the developer might assume that "force-inlining" a method call (essentially by stripping out the call itself and replacing with copied/pasted code) will be worthwhile, when in reality keeping the method call as-is would result in its getting inlined by the compiler only when it makes sense (when the benefit of inlining outweighs the growth in code size).

This is only a general idea, of course. I don't have concrete code samples that I can point to; but maybe you can scrounge some up if you look for them.

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