首页 / 知识

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

2023-04-15 19:13:00

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

What attributes help runtime .Net performance?

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

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

1
[Debuggable(false, false)]

还有其他我应该知道的吗?


Ecma-335在附件F"不精确的错误"中为放松的异常处理(所谓的电子松弛调用)指定了更多的CompilationRelaxation,但是Microsoft尚未公开它们。

那里特别提到了CompilationRelaxations.RelaxedArrayExceptions和CompilationRelaxations.RelaxedNullReferenceException。

当您在CompilationRelaxationsAttribute的ctor中尝试一些整数时,将会发生什么呢?


另一个:默认情况下,文字字符串(在源代码中声明的字符串)会嵌入到池中以节省内存。

1
2
3
4
5
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编译器您确实不希望它内生所有文字字符串。

1
[assembly: CompilationRelaxations(CompilationRelaxations.NoStringInterning)]


我找到了另一个:NeutralResourcesLanguageAttribute。根据此博客文章,它通过指定当前(中性)装配的区域性来帮助装载机更快地找到合适的卫星装配。

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


性能运行属性确保

最新内容

相关内容

猜你喜欢