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

pkg/query: relative comparisons #4578

Merged
merged 8 commits into from
Jul 4, 2024
Merged

pkg/query: relative comparisons #4578

merged 8 commits into from
Jul 4, 2024

Conversation

metalmatze
Copy link
Member

When comparing profiles, people usually want to compare relatively, meaning they care about the relative percentages that changed between the profiles, not about the exact times a stack has been seen.
This change ensures that we scale both profiles to the same total cumulative value for the root and then multiply each diff value by the ratio between both roots.

Comment on lines 773 to 828
diff := multiplyInt64By(mem, columns[len(columns)-4].(*array.Int64), -1*cumulativeRatio)
defer diff.Release()
diffPerSecond := multiplyFloat64By(mem, columns[len(columns)-3].(*array.Float64), -1)
diffPerSecond := multiplyFloat64By(mem, columns[len(columns)-3].(*array.Float64), -1*cumulativePerSecondRatio)
Copy link
Member Author

Choose a reason for hiding this comment

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

Right now, only this side of the comparison is changed. However, if this side has the higher total cumulative value, we need to "scale" it down. Meaning that we sometimes calculate new values with 1 * 0.95 which results in 0 for the int64 columns.
In that case, we probably should instead "scale" the other side up, right? Basically making it a calculation of 1 * 1.05 which would still be 1 once casted back to int64.

Copy link

alwaysmeticulous bot commented May 6, 2024

🤖 Meticulous spotted visual differences in 37 of 498 screens tested: view and approve differences detected.

Last updated for commit 3f4cb5c. This comment will update as new commits are pushed.

@metalmatze metalmatze changed the title WIP: pkg/query: relative comparisons pkg/query: relative comparisons May 7, 2024
@metalmatze
Copy link
Member Author

Now, we need to figure out the UX and UI to enable or disable the relative comparison.
Most likely, a toggle that will show when comparing makes the most sense.

pkg/query/columnquery.go Outdated Show resolved Hide resolved
pkg/query/columnquery.go Outdated Show resolved Hide resolved
Copy link
Member

@brancz brancz left a comment

Choose a reason for hiding this comment

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

This largely looks good except for one small comment, but I'm actually more wondering about the UX of this, as we have plenty of evidence that suggests that people want to do both absolute and relative comparisons, depending on the situation, so we should allow users to do both, but with this patch we'd only allow them to do relative comparisons.

} else {
cumulativeCompareRatio = float64(totalBaseValue) / float64(totalCompareValue)
}
if totalCompareValuePerSecond > totalBaseValuePerSecond {
Copy link
Member

Choose a reason for hiding this comment

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

Having two if statements here doesn't make sense to me, that would mean we can have a situation where we're scaling cumulative based on one side and per second on the other. We should always scale the same side.

When comparing profiles, people usually want to compare relatively, meaning they care about the relative percentages that changed between the profiles, not about the exact times a stack has been seen.
This change ensures that we scale both profiles to the same total cumulative value for the root and then multiply each diff value by the ratio between both roots.
This indicates whether or not to use absolute or relative profile comparison.
This now sums up the total cumulative value of each side before scaling up the smaller side to match the overall cumulative value of the bigger side.
… comparison

For delta profiles we want to use relative comparisons by default, whereas for non-delta profiles, we want to use absolute comparisons by default.
@metalmatze
Copy link
Member Author

Absolute

This shows the absolute comparison between the two profiles.
It is what we have had all along. It'll be the default for all non-delta profiles (goroutine, memory).
absolute

Relative

This shows the relative comparison of the two profiles. The smaller (in terms of overall cumulative value) profile gets scaled up (all of its values are multiplied by the factor the bigger profile is bigger) to have both profiles' total cumulative values be the same. Therefore, compare the percentage between all functions of both profiles.

relative

Copy link
Contributor

@yomete yomete left a comment

Choose a reason for hiding this comment

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

lgtm!

@metalmatze metalmatze merged commit ae7ba1a into main Jul 4, 2024
38 checks passed
@metalmatze metalmatze deleted the compare-relative branch July 4, 2024 14:49
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.

3 participants