Skip to content

Conversation

beorn7
Copy link
Member

@beorn7 beorn7 commented Jun 24, 2025

See commit description for details, also the discussion in #16714 .

(The very short version is that I was wrong assuming that the incremental mean calculation combined with Kahan summation in the improved way introduced in #16569 is always at least as good as the previous approach.)

/cc @charleskorn @crush-on-anechka

Copy link
Member

@krajorama krajorama left a comment

Choose a reason for hiding this comment

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

LGTM, but I'm not super familiar with the subject, suggest another pair of eyes

@beorn7
Copy link
Member Author

beorn7 commented Jun 25, 2025

Cleaned up the commits.

@beorn7
Copy link
Member Author

beorn7 commented Jun 25, 2025

@charleskorn might be a suitable reviewer. (His findings triggered ultimately triggered this.)

@bboreham
Copy link
Member

Can you summarise what the net difference of #16569 and this PR is, besides adding tests?

@beorn7
Copy link
Member Author

beorn7 commented Jun 25, 2025

Can you summarise what the net difference of #16569 and this PR is, besides adding tests?

I did that in the commit description:

This commit brings back direct mean calculation (for `avg` and
`avg_over_time`) but isn't an outright revert of https://github.com/prometheus/prometheus/pull/16569. It keeps the
improved incremental mean calculation and features generally a bit
cleaner code than before.

Also, this commit...

- ...updates the lengthy comment explaining the whole situation and
  trade-offs.

- ...divides the running sum and the Kahan compensation term
  separately (in direct mean calculation) to avoid the (unlikely)
  possibility that sum and Kahan compensation together overflow
  float64.

- ...uncomments the tests that should now work again on darwin/arm64.

- ...uncomments the test that should now reliably yield the
  (inaccurate) value 0 on all hardware platforms. Also, the test
  description has been updated accordingly.

- ...adds avg_over_time tests for zero and one sample in the range.

Copy link
Contributor

@charleskorn charleskorn left a comment

Choose a reason for hiding this comment

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

LGTM modulo suggestion for another test case.

Thanks for fixing this @beorn7.

beorn7 added 3 commits June 27, 2025 14:34
These demonstrate that direct mean calculation has some merits after
all.

Signed-off-by: beorn7 <beorn@grafana.com>
The test in question actually worked fine even before #16569. The
finding reported in the comment has turned out to be caused by
something else.

Signed-off-by: beorn7 <beorn@grafana.com>
This commit brings back direct mean calculation (for `avg` and
`avg_over_time`) but isn't an outright revert of #16569. It keeps the
improved incremental mean calculation and features generally a bit
cleaner code than before.

Also, this commit...

- ...updates the lengthy comment explaining the whole situation and
  trade-offs.

- ...divides the running sum and the Kahan compensation term
  separately (in direct mean calculation) to avoid the (unlikely)
  possibility that sum and Kahan compensation together ovorflow
  float64.

- ...uncomments the tests that should now work again on darwin/arm64.

- ...uncomments the test that should now reliably yield the
  (inaccurate) value 0 on all hardware platforms. Also, the test
  description has been updated accordingly.

- ...adds avg_over_time tests for zero and one sample in the range.

Signed-off-by: beorn7 <beorn@grafana.com>
@beorn7
Copy link
Member Author

beorn7 commented Jun 27, 2025

Thanks. I'll merge on green.

@beorn7 beorn7 enabled auto-merge June 27, 2025 12:35
@beorn7 beorn7 merged commit 9e73fb4 into main Jun 27, 2025
43 checks passed
@beorn7 beorn7 deleted the beorn7/promql branch June 27, 2025 12:57
crush-on-anechka added a commit to crush-on-anechka/prometheus that referenced this pull request Jul 10, 2025
Signed-off-by: Aleksandr Smirnov <5targazer@mail.ru>
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.

4 participants