-
Notifications
You must be signed in to change notification settings - Fork 415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fastdelta: reduce allocs by up to 90% #1559
fastdelta: reduce allocs by up to 90% #1559
Conversation
Avoid calling sort.Sort which allocates due to the slice to interface conversion. Also simplify the hashing a bit, no need to hash the location list and then re-hash it again, it can all go into the same hash right away. $ benchstat before.txt after.txt name old time/op new time/op delta FastDelta/testdata/heap.pprof-12 923µs ± 1% 833µs ± 1% -9.75% (p=0.000 n=9+10) FastDelta/testdata/big-heap.pprof-12 11.6ms ± 1% 10.5ms ± 2% -9.32% (p=0.000 n=9+9) name old alloc/op new alloc/op delta FastDelta/testdata/heap.pprof-12 199kB ± 0% 175kB ± 0% -12.02% (p=0.000 n=10+10) FastDelta/testdata/big-heap.pprof-12 1.80MB ± 0% 1.53MB ± 0% -15.11% (p=0.000 n=10+10) name old allocs/op new allocs/op delta FastDelta/testdata/heap.pprof-12 1.17k ± 0% 0.18k ± 0% -84.86% (p=0.000 n=8+10) FastDelta/testdata/big-heap.pprof-12 12.5k ± 0% 1.2k ± 0% -90.61% (p=0.000 n=10+10)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I'm a little surprised because I thought it was sort.Slices
was what caused allocations, which we got rid of with #1512. 🤷
We can get a similar benefit by making
|
Fascinating. That was actually the first thing I tried, but I did Seems like my version compiled to:
Whereas yours compiles to
I'm not sure I fully understand why this is happening. If you do, please share. Either way, I'll update this to use your version. |
vscode actually tab-completed |
Co-authored-by: Nick Ripley <97066770+nsrip-dd@users.noreply.github.com>
I think the reason this works is that by passing the address of |
Yeah, that's what I figured from looking at |
I think I understand it now. There is no language spec reason for this. It's simply the heap escape analysis not being powerful enough to understand that the copy of the slice header doesn't have to escape to the heap. |
Avoid calling sort.Sort which allocates due to the slice to interface conversion.
Also simplify the hashing a bit, no need to hash the location list and then re-hash it again, it can all go into the same hash right away.