-
Notifications
You must be signed in to change notification settings - Fork 690
Reduce memory allocations when rendering diff flamegraphs #4430
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
Conversation
823d341
to
1cc19b9
Compare
|
||
h := make([]int64, 0, maxNodes) | ||
combineIterateWithTotal(leftTree, rightTree, func(left uint64, right uint64) bool { | ||
return c.Push(max(left, right)) | ||
maxVal := int64(max(left, right)) | ||
if len(h) >= maxNodes { | ||
if maxVal > h[0] { | ||
h = minheap.Pop(h) | ||
h = minheap.Push(h, maxVal) | ||
} | ||
} else { | ||
h = minheap.Push(h, maxVal) | ||
} | ||
return true | ||
}) | ||
return c.MinValue() | ||
|
||
if len(h) < maxNodes { | ||
return 0 | ||
} | ||
return uint64(h[0]) |
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.
this is based on model.Tree.minValue()
, adapted for 2 trees
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.
LGTM
Thanks for spotting this. Wonder how "good" your benchmarks were, but might make sense to add them.
I can't add the data I used for the benchmark, but I can likely capture the improvement with synthetic data as well. I will add the benchmark code before merging. Edit: done |
When we render large diff flamegraphs, we create quite a bit of allocations due to prepending to a slice instead of appending. We also use an older and less efficient way of truncating the diff tree, I've replaced that with the one used for truncating regular (non-diff) trees