c# - 委托(delegate)创建缓慢

标签 c# delegates resharper

我升级了 ReSharper 并看到了一个我以前没有出现过的错误。我四处查看,但没有发现任何有关错误或它标记的潜在问题的信息。

** 编辑 **:正如下面所指出的,它实际上是“堆分配查看器”插件,而不是 ReSharper 本身将其标记为错误——尽管这不会改变问题本身。

Slow delegate creation: from interface 'IPluginHandler' method

这发生在插件处理程序订阅事件聚合器上的事件期间。

public void Subscribe(IPluginHandler subscriber)
{
  Executing += subscriber.OnExecuting;
  // -- additional subscriptions --
}

在上面的代码中,Executing 是一个事件,subscriber.OnExecuting 是该事件的适当事件处理程序。

需要明确的是,这是一个 ReSharper“软错误”,因为代码仍会按预期构建和运行。

所以我的问题是 JetBrains 的优秀人员为我提出的根本问题是什么,它的后果是什么。

谢谢

最佳答案

This JetBrains blog post在评论中有同样的问题。

那里的回复是这样说的:

Hi! This plugin also has one more internal feature: code inspection to show ‘slow’ (>10x slower) delegate instance creations for CLR x86 JIT. You can run this test (it creates delegates from various kinds of methods – virtual/interface/generic/etc) to see the difference in delegate creation performance.

Just as with allocations inspection – you shouldn’t care about this much until some performance snapshot in some hot path of your application shows long invocations of CLR internals. And just like with allocations – this inspections may (and will) produce false positives with new RuyJIT, for example.

请注意 linked test用箭头注释突出显示“缓慢”的委托(delegate)创建:<-- .

关于c# - 委托(delegate)创建缓慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26390745/

相关文章:

c# - 将对象转换为通用列表

c# - 使用委托(delegate)时,有没有办法获取对象响应?

c# - 如何以正确的方式使用委托(delegate)/了解委托(delegate)

c# - 添加到方法组是否算作使用变量?

javascript - VS2008 正在 .js 文件中自动格式化我的 javascript,我希望它停止

c# - MVC - 使用 C# 用 Json 操作结果填充 ViewBag

c# - MEF RegistrationBuilder 导出特定接口(interface)实现

ios - 委托(delegate)如何知道在有多个一致性的地方调用函数

c# - 键入时缺少 Visual Studio 2013 智能感知快速信息

c# - 隐藏 GridView 中的特定单元格