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

Prevent unnecessary heap sort when buckets needs to be ordered by key… #17252

Merged
merged 1 commit into from
Feb 6, 2025

Conversation

rishabhmaurya
Copy link
Contributor

@rishabhmaurya rishabhmaurya commented Feb 5, 2025

We can slightly improve performance of Numeric term Aggs by avoiding double sorting - first by count and then by key before final reduce

Description

We don't need to sort the buckets by _count. PriorityQueue will ensure topN buckets by _count, as final reduce order is always by key in NumericTermsAggregation and ResultStrategy#buildResult() is anyways sorting the buckets by key before final reduce, thus sorting the buckets by count or whatever the order clause was, is redundant.

Related Issues

Resolves #[Issue number to be closed when this PR is merged]

Check List

  • Functionality includes testing.
    - [ ] API changes companion pull request created, if applicable.
    - [ ] Public documentation issue/PR created, if applicable.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@rishabhmaurya
Copy link
Contributor Author

@msfroh Please let me know if this change looks legit to you, thank you

Copy link
Contributor

github-actions bot commented Feb 5, 2025

❌ Gradle check result for b007591: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

… in NumericTermsAggregation

Signed-off-by: Rishabh Maurya <rishabhmaurya05@gmail.com>
Copy link
Contributor

github-actions bot commented Feb 5, 2025

✅ Gradle check result for 6141759: SUCCESS

Copy link

codecov bot commented Feb 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 72.29%. Comparing base (865704b) to head (6141759).
Report is 16 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main   #17252      +/-   ##
============================================
- Coverage     72.43%   72.29%   -0.14%     
+ Complexity    65725    65710      -15     
============================================
  Files          5318     5318              
  Lines        305675   305680       +5     
  Branches      44350    44352       +2     
============================================
- Hits         221408   220999     -409     
- Misses        66055    66597     +542     
+ Partials      18212    18084     -128     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@msfroh msfroh left a comment

Choose a reason for hiding this comment

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

Wow... That's subtle. Replacing the O(log n) pop with the O(1) next is a good find (for sufficiently large n)!

@rishabhmaurya rishabhmaurya added backport PRs or issues specific to backporting features or enhancments backport 2.x Backport to 2.x branch labels Feb 6, 2025
@rishabhmaurya
Copy link
Contributor Author

@msfroh looks like you already approved, if you do not have any concerns, we can merge it.

@jainankitk jainankitk merged commit 3f793b6 into opensearch-project:main Feb 6, 2025
64 of 66 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Feb 6, 2025
… in NumericTermsAggregation (#17252)

Signed-off-by: Rishabh Maurya <rishabhmaurya05@gmail.com>
(cherry picked from commit 3f793b6)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
rishabhmaurya added a commit to rishabhmaurya/OpenSearch that referenced this pull request Feb 11, 2025
… in NumericTermsAggregation (opensearch-project#17252)

Signed-off-by: Rishabh Maurya <rishabhmaurya05@gmail.com>
(cherry picked from commit 3f793b6)
msfroh pushed a commit that referenced this pull request Feb 11, 2025
… in NumericTermsAggregation (#17252) (#17290)

(cherry picked from commit 3f793b6)

Signed-off-by: Rishabh Maurya <rishabhmaurya05@gmail.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Signed-off-by: Ankit Jain <akjain@amazon.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Ankit Jain <akjain@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport PRs or issues specific to backporting features or enhancments backport 2.x Backport to 2.x branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants