Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

runtime.duffcopy is called a lot

Tags:

go

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

like image 807
erken Avatar asked Aug 20 '17 20:08

erken


1 Answers

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 < 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 :)

like image 137
erken Avatar answered Oct 22 '22 00:10

erken