Skip to content

Conversation

@lukaville
Copy link
Contributor

@lukaville lukaville commented Nov 28, 2025

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

image

@github-actions
Copy link

github-actions bot commented Nov 28, 2025

🎨 Perfetto UI Build

✅ UI build is ready: https://storage.googleapis.com/perfetto-ci-artifacts/gh-19829868466-ui/ui/index.html

@lukaville lukaville changed the title Heap flamegraph: sort roots to improve stability Heap flamegraph: sort roots by name to improve stability Dec 1, 2025
@lukaville lukaville marked this pull request as ready for review December 1, 2025 16:30
@lukaville lukaville requested a review from a team as a code owner December 1, 2025 16:30
@lukaville lukaville requested a review from nicomazz December 1, 2025 16:30
Copy link
Member

@LalitMaganti LalitMaganti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ilkos for comments.

}

std::unique_ptr<tables::ExperimentalFlamegraphTable>
HeapGraphTracker::BuildFlamegraph(const int64_t current_ts,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like the wrog place to do this. Sure it will work for pprof but then pprofs will not be consistent with the Perfetto UI.

Also experimental_flamegraph is intended for deletion with the pprof export code being rebased on top of the same code the UI uses: at that point again this will break.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I thought experimental_flamegraph is also used in the UI. Would it make sense to introduce similar change to both experimental_flamegraph and whatever the UI currently uses?

Seems like currenlty UI uses _heap_graph_object_min_depth_tree for this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes _heap_graph_object_min_depth_tree is what you would need to modify.

@LalitMaganti LalitMaganti requested a review from ilkos December 1, 2025 16:34
@lukaville lukaville marked this pull request as draft December 1, 2025 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants