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

Speed up EntrySortIterator by 20%. #5318

Merged
merged 14 commits into from
Feb 9, 2022

Conversation

jeschkies
Copy link
Contributor

@jeschkies jeschkies commented Feb 3, 2022

What this PR does / why we need it:
This patch replace the underlying heap of the EntrySortIterator. Instead of using a min or max heap the entry iterators are sorted at the beginning. Once the iteration starts only the first entry iterator is re-positioned depending on its current value. This will yield the same runtime complexity as the current heap based solution. However, since the new algorithm accesses the first element it can be cached. Thus the number of access calls to Entry().Timestamp are halved.

› benchstat before.txt after.txt
name                        old time/op  new time/op  delta
SortIterator/merge_sort-16  4.40ms ± 4%  4.38ms ± 3%     ~     (p=0.400 n=9+10)
SortIterator/sort-16        3.65ms ± 2%  2.80ms ± 3%  -23.25%  (p=0.000 n=9+10)

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

Checklist

  • Documentation added
  • Tests updated
  • Add an entry in the CHANGELOG.md about the changes.

@jeschkies jeschkies requested a review from a team as a code owner February 3, 2022 16:13
pkg/iter/entry_iterator.go Outdated Show resolved Hide resolved
pkg/iter/entry_iterator.go Outdated Show resolved Hide resolved
pkg/iter/entry_iterator.go Outdated Show resolved Hide resolved
pkg/iter/entry_iterator.go Outdated Show resolved Hide resolved
vendor/modules.txt Outdated Show resolved Hide resolved
Copy link
Contributor

@cyriltovena cyriltovena left a comment

Choose a reason for hiding this comment

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

Looking good please make sure you correctly merge freshly change there.

@jeschkies jeschkies changed the title Speed up EntrySortIterator by 20%. Speed up EntrySortIterator by 25%. Feb 4, 2022
@pull-request-size pull-request-size bot added size/M and removed size/L labels Feb 4, 2022
@pull-request-size pull-request-size bot added size/L and removed size/M labels Feb 4, 2022
@jeschkies jeschkies changed the title Speed up EntrySortIterator by 25%. Speed up EntrySortIterator by 20%. Feb 4, 2022
pkg/iter/entry_iterator.go Outdated Show resolved Hide resolved
pkg/iter/entry_iterator.go Outdated Show resolved Hide resolved
Copy link
Contributor

@cyriltovena cyriltovena left a comment

Choose a reason for hiding this comment

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

LGTM

@jeschkies jeschkies merged commit 8e9009a into grafana:main Feb 9, 2022
@jeschkies jeschkies deleted the karsten/sort-iterator branch February 9, 2022 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants