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

Store gateway mmap removal: use SkipUvarintBytes() and simplify logic in PostingsOffset() #3787

Merged
merged 8 commits into from
Dec 23, 2022

Conversation

charleskorn
Copy link
Contributor

@charleskorn charleskorn commented Dec 21, 2022

What this PR does

This PR contains two changes:

  • it replaces the instances where we use UnsafeUvarintBytes() with SkipUvarintBytes(), which has a negligible performance impact but clarifies intent
  • it simplifies the logic in PostingsOffset() to only support retrieving the byte range for a single name/value pair, as this is all we do at present

This second change, in addition to making the code easier to read, also gives us a modest performance improvement:

name                                 old time/op    new time/op    delta
PostingsOffset/20Names100Values-10     11.7µs ± 1%    11.6µs ± 1%     ~     (p=0.151 n=5+5)
PostingsOffset/20Names500Values-10     11.7µs ± 0%    11.5µs ± 0%   -1.44%  (p=0.008 n=5+5)
PostingsOffset/20Names1000Values-10    11.7µs ± 0%    11.6µs ± 1%   -1.22%  (p=0.008 n=5+5)

name                                 old alloc/op   new alloc/op   delta
PostingsOffset/20Names100Values-10       385B ± 0%      337B ± 0%  -12.47%  (p=0.000 n=5+4)
PostingsOffset/20Names500Values-10       385B ± 0%      337B ± 0%  -12.47%  (p=0.000 n=5+4)
PostingsOffset/20Names1000Values-10      385B ± 0%      337B ± 0%  -12.47%  (p=0.008 n=5+5)

name                                 old allocs/op  new allocs/op  delta
PostingsOffset/20Names100Values-10       10.0 ± 0%       7.0 ± 0%  -30.00%  (p=0.008 n=5+5)
PostingsOffset/20Names500Values-10       10.0 ± 0%       7.0 ± 0%  -30.00%  (p=0.008 n=5+5)
PostingsOffset/20Names1000Values-10      10.0 ± 0%       7.0 ± 0%  -30.00%  (p=0.008 n=5+5)

If we do ever want to take advantage of the fact we can retrieve multiple ranges at once, we can always revert this change.

Which issue(s) this PR fixes or relates to

Relates to #3465, builds upon #3742.

Checklist

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

The performance impact is negligible, but this better conveys our
intent.
The performance impact is negligible, but this better conveys our
intent.
At present, we only ever look up a single value at once, and we
gain a small performance boost by simplifying the logic:

name                                 old time/op    new time/op    delta
PostingsOffset/20Names100Values-10     11.7µs ± 1%    11.6µs ± 1%     ~     (p=0.151 n=5+5)
PostingsOffset/20Names500Values-10     11.7µs ± 0%    11.5µs ± 0%   -1.44%  (p=0.008 n=5+5)
PostingsOffset/20Names1000Values-10    11.7µs ± 0%    11.6µs ± 1%   -1.22%  (p=0.008 n=5+5)

name                                 old alloc/op   new alloc/op   delta
PostingsOffset/20Names100Values-10       385B ± 0%      337B ± 0%  -12.47%  (p=0.000 n=5+4)
PostingsOffset/20Names500Values-10       385B ± 0%      337B ± 0%  -12.47%  (p=0.000 n=5+4)
PostingsOffset/20Names1000Values-10      385B ± 0%      337B ± 0%  -12.47%  (p=0.008 n=5+5)

name                                 old allocs/op  new allocs/op  delta
PostingsOffset/20Names100Values-10       10.0 ± 0%       7.0 ± 0%  -30.00%  (p=0.008 n=5+5)
PostingsOffset/20Names500Values-10       10.0 ± 0%       7.0 ± 0%  -30.00%  (p=0.008 n=5+5)
PostingsOffset/20Names1000Values-10      10.0 ± 0%       7.0 ± 0%  -30.00%  (p=0.008 n=5+5)
@charleskorn charleskorn requested a review from a team as a code owner December 21, 2022 04:38
Copy link
Collaborator

@pracucci pracucci left a comment

Choose a reason for hiding this comment

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

From a quick look to the logic, it LGTM. I defer @56quarters for a deeper review.

pkg/storegateway/indexheader/index/postings.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@pracucci pracucci left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Copy link
Contributor

@56quarters 56quarters left a comment

Choose a reason for hiding this comment

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

LGTM

@pracucci
Copy link
Collaborator

@charleskorn Could you fix the conflict and then ping a maintainer to merge? 🙇

…e-skip

# Conflicts:
#	CHANGELOG.md
#	pkg/storegateway/indexheader/index/postings.go
}
rngs = append(rngs, newSameRngs...)
break
rng.End = e.lastValOffset
Copy link
Collaborator

Choose a reason for hiding this comment

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

[unrelated from this PR, non blocking] Given lastValOffset is used as the end range in case this is the last value for the given label name, I'm wondering if we could find a better name for lastValOffset, cause it sounds like "offset of the start of the last value" and not "offset of the end of the last value". Makes sense or am I missing something?

@pracucci pracucci merged commit b015861 into main Dec 23, 2022
@pracucci pracucci deleted the charleskorn/mmap-less-index-header-reader-use-skip branch December 23, 2022 04:29
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