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

MQE: don't create copies of native histogram during binary operations #10049

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

charleskorn
Copy link
Contributor

@charleskorn charleskorn commented Nov 29, 2024

What this PR does

This PR removes creating copies of native histogram during binary operations in MQE.

This dramatically improves the performance of binary operations involving native histograms, for example:

                                                                    │ original.txt  │              after.txt              │
                                                                    │    sec/op     │    sec/op     vs base               │
Query/nh_1_/_a_1,_instant_query/engine=Mimir-10                        312.2µ ±  1%   330.7µ ±  2%   +5.96% (p=0.002 n=6)
Query/nh_1_/_a_1,_range_query_with_100_steps/engine=Mimir-10           373.7µ ±  3%   374.2µ ±  2%        ~ (p=0.699 n=6)
Query/nh_1_/_a_1,_range_query_with_1000_steps/engine=Mimir-10         1051.5µ ±  2%   885.6µ ±  2%  -15.77% (p=0.002 n=6)
Query/nh_100_/_a_100,_instant_query/engine=Mimir-10                    5.440m ±  4%   5.268m ±  0%   -3.16% (p=0.002 n=6)
Query/nh_100_/_a_100,_range_query_with_100_steps/engine=Mimir-10      11.400m ±  5%   9.901m ±  1%  -13.15% (p=0.002 n=6)
Query/nh_100_/_a_100,_range_query_with_1000_steps/engine=Mimir-10      61.10m ±  5%   51.58m ±  1%  -15.58% (p=0.002 n=6)
Query/nh_2000_/_a_2000,_instant_query/engine=Mimir-10                 101.00m ±  7%   99.37m ±  5%        ~ (p=0.485 n=6)
Query/nh_2000_/_a_2000,_range_query_with_100_steps/engine=Mimir-10     204.6m ±  5%   178.1m ±  2%  -12.96% (p=0.002 n=6)
Query/nh_2000_/_a_2000,_range_query_with_1000_steps/engine=Mimir-10   1189.4m ±  1%   970.7m ±  5%  -18.39% (p=0.002 n=6)
Query/nh_1_/_2,_instant_query/engine=Mimir-10                          194.8µ ±  7%   182.9µ ±  3%   -6.08% (p=0.002 n=6)
Query/nh_1_/_2,_range_query_with_100_steps/engine=Mimir-10             269.9µ ±  6%   226.2µ ±  3%  -16.20% (p=0.002 n=6)
Query/nh_1_/_2,_range_query_with_1000_steps/engine=Mimir-10            870.9µ ±  3%   682.9µ ±  3%  -21.59% (p=0.002 n=6)
Query/nh_100_/_2,_instant_query/engine=Mimir-10                        4.700m ±  5%   4.525m ±  1%   -3.73% (p=0.002 n=6)
Query/nh_100_/_2,_range_query_with_100_steps/engine=Mimir-10          10.217m ±  1%   8.589m ±  1%  -15.93% (p=0.002 n=6)
Query/nh_100_/_2,_range_query_with_1000_steps/engine=Mimir-10          56.92m ±  6%   46.10m ±  1%  -19.02% (p=0.002 n=6)
Query/nh_2000_/_2,_instant_query/engine=Mimir-10                       85.43m ±  4%   83.10m ±  1%   -2.72% (p=0.002 n=6)
Query/nh_2000_/_2,_range_query_with_100_steps/engine=Mimir-10          179.7m ±  7%   153.1m ±  1%  -14.80% (p=0.002 n=6)
Query/nh_2000_/_2,_range_query_with_1000_steps/engine=Mimir-10        1091.5m ±  1%   820.6m ±  2%  -24.82% (p=0.002 n=6)

This has no noticeable impact on binary operations only on floats, and has no noticeable impact on peak memory consumption.

Which issue(s) this PR fixes or relates to

(none)

Checklist

  • [n/a] Tests updated.
  • [n/a] Documentation added.
  • [n/a] CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX].
  • [n/a] about-versioning.md updated with experimental features.

@charleskorn charleskorn force-pushed the charleskorn/mqe-nh-binop-copy-elimination branch from 269b429 to 6eef06d Compare December 4, 2024 05:16
@charleskorn charleskorn force-pushed the charleskorn/mqe-nh-binop-copy-elimination branch from 6eef06d to 0173b39 Compare December 12, 2024 21:58
@charleskorn charleskorn marked this pull request as ready for review December 12, 2024 22:19
@charleskorn charleskorn requested a review from a team as a code owner December 12, 2024 22:19
@charleskorn
Copy link
Contributor Author

charleskorn commented Dec 13, 2024

This is ready for a review, but will require changes to support group_left and group_right after #10119 is merged.

Copy link
Contributor

@jhesketh jhesketh 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 will approve once reworked with the group changes.

I haven't looked closely, but do we have good tests to that would fail if we weren't nil'ing values before returning to the pool appropriately? (Just thinking how we can better test this).

I also imagine this would not work if we every revisited trying not to copy histograms on lookbacks. It might be worth adding a comment somewhere as such.

@charleskorn charleskorn force-pushed the charleskorn/mqe-nh-binop-copy-elimination branch from 0173b39 to 0ac7576 Compare January 10, 2025 04:00
@@ -47,9 +47,9 @@ func (i *InstantVectorSeriesDataIterator) Reset(data InstantVectorSeriesData) {
// It returns the next point with the lowest timestamp.
// If h is not nil, the value is a histogram, otherwise it is a float.
// If no more values exist ok is false.
func (i *InstantVectorSeriesDataIterator) Next() (t int64, f float64, h *histogram.FloatHistogram, ok bool) {
func (i *InstantVectorSeriesDataIterator) Next() (t int64, f float64, h *histogram.FloatHistogram, hIndex int, ok bool) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about keeping this method as just returning the next values.

Then have a couple of extra methods to getCurrentHIndex / getCurrentFIndex ?

I feel like that would be neater and keep the methods clearer on their uses.

@charleskorn charleskorn force-pushed the charleskorn/mqe-nh-binop-copy-elimination branch from 0ac7576 to dba8be3 Compare January 17, 2025 06:04
@charleskorn charleskorn marked this pull request as draft January 17, 2025 06:10
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