哪些属性有助于运行时 .Net 性能?

发布于 2024-07-04 15:15:48 字数 289 浏览 4 评论 0原文

我正在寻找可用于通过向加载器、JIT 编译器或 ngen 提供提示来确保 .Net 应用程序获得最佳运行时性能的属性。

例如,我们有 DebuggableAttribute ,应将其设置为不调试且不禁用优化以获得最佳性能。

[Debuggable(false, false)]

还有其他我应该了解的吗?

I am looking for attributes I can use to ensure the best runtime performance for my .Net application by giving hints to the loader, JIT compiler or ngen.

For example we have DebuggableAttribute which should be set to not debug and not disable optimization for optimal performance.

[Debuggable(false, false)]

Are there any others I should know about?

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

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

发布评论

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

评论(3

Oo萌小芽oO 2024-07-11 15:15:48

我找到了另一个:NeutralResourcesLanguageAttribute。 根据 这篇 博客文章,它可以帮助加载程序通过指定当前(中性)程序集的区域性,可以更快地找到正确的附属程序集。

[NeutralResourcesLanguageAttribute("nl", UltimateResourceFallbackLocation.MainAssembly)]

I found another: NeutralResourcesLanguageAttribute. According to this blog post it helps the loader in finding the right satellite assemblies faster by specifying the culture if the current (neutral) assembly.

[NeutralResourcesLanguageAttribute("nl", UltimateResourceFallbackLocation.MainAssembly)]
月光色 2024-07-11 15:15:48

另一个:文字字符串(在源代码中声明的字符串)默认为 驻留到池中以节省内存。

string s1 = "MyTest"; 
string s2 = new StringBuilder().Append("My").Append("Test").ToString(); 
string s3 = String.Intern(s2); 
Console.WriteLine((Object)s2==(Object)s1); // Different references.
Console.WriteLine((Object)s3==(Object)s1); // The same reference.

虽然多次使用同一个文字字符串时可以节省内存,但维护池会花费一些 cpu,并且一旦将字符串放入池中,它就会一直保留在那里,直到进程停止。

使用 CompilationRelaxationsAttribute 你可以告诉 JIT 编译器你真的不希望它保留所有的文字字符串。

[assembly: CompilationRelaxations(CompilationRelaxations.NoStringInterning)]

And another: Literal strings (strings declared in source code) are by default interned into a pool to save memory.

string s1 = "MyTest"; 
string s2 = new StringBuilder().Append("My").Append("Test").ToString(); 
string s3 = String.Intern(s2); 
Console.WriteLine((Object)s2==(Object)s1); // Different references.
Console.WriteLine((Object)s3==(Object)s1); // The same reference.

Although it saves memory when the same literal string is used multiple times, it costs some cpu to maintaining the pool and once a string is put into the pool it stays there until the process is stopped.

Using CompilationRelaxationsAttribute you can tell the JIT compiler that you really don't want it to intern all the literal strings.

[assembly: CompilationRelaxations(CompilationRelaxations.NoStringInterning)]
临走之时 2024-07-11 15:15:48

Ecma-335 在附件 F“不精确的错误”中指定了更多用于宽松异常处理(所谓的 e-relaxed 调用)的 CompilationRelaxations,但 Microsoft 尚未公开它们。

具体来说,那里提到了 CompilationRelaxations.RelaxedArrayExceptions 和 CompilationRelaxations.RelaxedNullReferenceException 。

当您在 CompilationRelaxationsAttribute 的构造函数中尝试一些整数时,会发生什么,这会很有趣;)

Ecma-335 specifies some more CompilationRelaxations for relaxed exception handling (so-called e-relaxed calls) in Annex F "Imprecise faults", but they have not been exposed by Microsoft.

Specifically CompilationRelaxations.RelaxedArrayExceptions and CompilationRelaxations.RelaxedNullReferenceException are mentioned there.

It'd be intersting what happens when you just try some integers in the CompilationRelaxationsAttribute's ctor ;)

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