Fix histogram scrape performance#219
Conversation
When profiling histogram scraping I discovered that the major bottleneck is creating a clone of the accumulator in reduce. We should not actually need to skip mutation.
| function addSumAndCountForExport(histogram) { | ||
| return (acc, d) => { | ||
| acc = acc.concat(d.buckets); | ||
| acc.push.apply(acc, d.buckets); |
There was a problem hiding this comment.
why not just acc.push(d.buckets);?
There was a problem hiding this comment.
oh, it's an array. makes sense :)
There was a problem hiding this comment.
it can be acc.push(...d.buckets);, we have a minimum node version of 6
There was a problem hiding this comment.
yeah, I didn't look up minimum node version, I had it that way initially but then decided to start off with more support. I'll update to the ES6 syntax.
|
Thanks for the PR! Mind updating the changelog as well? |
Done |
|
Thanks for the merge @SimenB! I did not package bump because I assume that you do that as part of your release process. Thanks for the great package, and for such a quick response! |
|
It's released as 11.1.2 now 🙂 |
❤️ thanks!!! |
|
So nice!! Thank you! ❤️ |
When profiling histogram scraping I discovered that the major bottleneck is creating a clone of the accumulator in reduce. We should not actually need to skip mutation.
You can see the benchmark of
concatvspushhere: https://codeburst.io/jsnoob-push-vs-concat-basics-and-performance-comparison-7a4b55242fa9This should address #216
I used this test script to profile.
Which resulted in before this patch of
7.021sand after of0.501s