我已经介绍过了,现在我正在寻找可以从我的热点中挤出一切可能的性能.
我知道[MethodImplOptions.AggressiveInlining]和ProfileOptimization类.还有其他人吗?
[编辑] 我刚刚发现了[TargetedPatchingOptOut].没关系,显然不需要一个.
MethodImplAttribute与选项MethodImplOptions.AggressiveInlining
和TargetedPatchingOptOut
?之间有什么区别?
当我在Google上搜索时,每个人似乎都说(可能)内联方法但没有给出差异.
正如在另一个问题中所解释的,如果方法设置了TargetedPatchingOptOutAttribute,则通常只允许Ngen跨组件内联方法.
但是,通过使用DependencyAttribute,对于硬绑定程序集也是如此吗?LoadHint.Always
编辑:也许我的初始问题的答案是否定的,否则TargetedPatchingOptOutAttribute
在mscorlib中使用它是没有意义的,因为这个程序集总是硬绑定(它设置了DefaultDependencyAttribute).所以我想重新解释一下我的问题:是否可以在TargetedPatchingOptOutAttribute
组件的原生图像中内联方法?
MarkupExtension 类的反编译如下所示:
[TypeForwardedFrom("WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")]
public abstract class MarkupExtension
{
[TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
protected MarkupExtension()
{
}
public abstract object ProvideValue(IServiceProvider serviceProvider);
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,它本来可以作为接口实现,但它是一个类。WPF 团队为什么要这样设计?而且,在Silverlight中它是一个接口。
在代码中定义了ValidateRequest方法
private bool ValidateRequest()
{
return _doc != null;
}
Run Code Online (Sandbox Code Playgroud)
从我想要检查_doc是否为null的所有地方调用此方法.此方法已在cs文件中使用了5次.
从性能的角度来看,建议只用一条线来定义一个方法是明智的吗?我认为在调用这个方法之前,所有来自被调用的东西都会被推到堆栈上,之后它会被从堆栈中拉出来.
有什么想法吗?
===编辑====
我使用的是.NET 3.5版
.net ×4
c# ×4
ngen ×2
optimization ×2
inline ×1
jit ×1
performance ×1
vb.net ×1
wpf ×1
xaml ×1