runtime.duffcopy被频繁调用。

huangapple go评论149阅读模式
英文:

runtime.duffcopy is called a lot

问题

当我对我的应用程序进行分析并运行top命令时,我看到以下输出:

显示前10个节点中的31个节点(cum >= 0.12s)
flat flat% sum% cum cum%
13.93s 63.00% 63.00% 13.93s 63.00% runtime.duffcopy

我很难知道它是何时以及为什么被调用的,是否有什么方法可以改进它?您是否需要查看调用这些函数的函数,或者是否有任何一般性的经验法则我应该考虑?

我已经阅读到命名返回值可以改进这个问题,但这是一个相当大的函数,测试了很多条件(返回true或false),所以不知道是否实施这个方法是一个好主意。

谢谢。

英文:

When profiling my app, and run top, I see

Showing top 10 nodes out of 31 (cum >= 0.12s)
      flat  flat%   sum%        cum   cum%
    13.93s 63.00% 63.00%     13.93s 63.00%  runtime.duffcopy

I am struggling to know when and why it is called and if there is something I can do to improve this? Would you need to see the function from where these calls are made from or is there any general rule-of-thumb that I should think about?

I have read that named return values can improve this, but its quite a big function testing a lot of conditions (returning true or false), so don't know if its a good idea to implement that.

Thanks

答案1

得分: 12

我刚刚解决了这个问题。我查看了汇编输出,发现我有一个循环:

for _, v := range c.Items

一个Item对象相对较大,所以我用下面的循环替换了上面的循环:

for index := 0; index < len(c.Items); index++

并且直接访问对象,如c.Items[index]。现在顶部显示:

350ms  4.85% 60.47%      350ms  4.85%  runtime.duffcopy

整体执行时间从12秒减少到4秒。非常不错 runtime.duffcopy被频繁调用。

英文:

Think I just solved it. I had a look at the assembly output and saw that I had a

for _, v := range c.Items

an Item is a relatively big object, so I replaced above loop with

for index := 0; index &lt; len(c.Items); index++

and used direct access of the objects like c.Items[index]. Top now shows:

350ms  4.85% 60.47%      350ms  4.85%  runtime.duffcopy

The overall execution time was cut from 12s to 4s. Quite nice runtime.duffcopy被频繁调用。

huangapple
  • 本文由 发表于 2017年8月21日 04:52:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/45786687.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定