Heap flamegraph: sort roots by name to improve stability
Currently often the GC root could be chosen non-deterministically (based on the row number) when calculating shortest path to the GC root in java heap flamegraph table.
Sorting them by name could improve stability for the cases when we want to compare heap dumps. We might consider sorting all sibling nodes by name when calculating path to roots, but currently it seems like root instability causes the biggest problem. Added only sorting of the roots in this PR to ensure minimum impact on performance.
E.g. in these two traces dalvik.system.PathClassLoader has exactly the same set of GC roots that reference it but we chose different roots, this causes issues when trying to compare the trees (they are treated as completely separate subtrees):
🎨 Perfetto UI Build
✅ UI build is ready: https://storage.googleapis.com/perfetto-ci-artifacts/gh-19969806058-ui/ui/index.html
At the same time I do wonder if this is the right traversal for your use case or whether you should be using a dominator tree comparison which is going to be much clearer, deterministic and easy to understand.
Yes, I agree that dominator traversal seems like a better fit for this, possibly it should be shown by default, we will be looking into adding this (this is in the context of Android SystemUI lab performance regression infrastructure). I have tried it and it works quite well but I think users should still have an option to choose either of the traversals.
The main downside from what I have seen is that with the dominator tree parent-child relations might not match the actual heap graph references which might be confusing. When with the shortest path traversal there is an actual reference shown to the user (even though it might be not the only one)
so imho it would be better to support both options and based on practical regressions we would be able to decide which one works better