Skip to content
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

Flamegraph: Update threshold for collapsing and fix flickering #78206

Merged
merged 5 commits into from
Nov 15, 2023

Conversation

aocenas
Copy link
Member

@aocenas aocenas commented Nov 15, 2023

What is this feature?

Before the collapsing groups in flamegraph were done only in cases parent and child had the same value. This was pretty strict and with lot's of samples even very thin wrapper code could accrue some difference in value so this changes the default threshold to min 0.99 of the parent.

Also this synchronizes the creation of the collapse map and other data so that the flamegraph is rendered with the collapsed groups on first render.

Why do we need this feature?

[Add a description of the problem the feature is trying to solve.]

Who is this feature for?

[Add information on what kind of user the feature is for.]

Which issue(s) does this PR fix?:

Fixes #

Special notes for your reviewer:

Please check that:

  • It works as expected from a user's perspective.
  • If this is a pre-GA feature, it is behind a feature toggle.
  • The docs are updated, and if this is a notable improvement, it's added to our What's New doc.

useEffect(() => {
if (data) {
setCollapsedMap(data.getCollapsedMap());

let levels = data.getLevels();
Copy link
Member Author

Choose a reason for hiding this comment

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

Instead of useMap for the collapseMap and separate useEffect for the levels computation this is done in single effect which synchronizes those 2 values and prevent flickering on double rerenders.

@@ -82,22 +77,6 @@ export function nestedSetToLevels(
level: currentLevel,
};

if (options?.collapsing) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This logic was moved to separate class for easier testing and also the whole logic was moved to after whole tree is computed. Otherwise we could not use any heuristic about how many children a parent can have as we don't have all the children at this point of the code.

}
}

addTree(root: LevelItem) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Because we need to know how many children item has we need to wait for the whole tree to be done and than do another pass over it.

Copy link
Contributor

@joey-grafana joey-grafana left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@aocenas aocenas merged commit 9777da5 into main Nov 15, 2023
18 checks passed
@aocenas aocenas deleted the aocenas/flamegraph/collapse-threshold-update branch November 15, 2023 16:59
@aangelisc aangelisc modified the milestones: 10.3.x, 10.2.3 Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants