-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
logstore: pool MVCCStats to avoid hot path allocs #113742
Conversation
It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR? 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
33530bc
to
a176594
Compare
Before this commit, logstore.logAppend allocated MVCCStats on heap despite its lifetime being confined within this function's scope. This commit switches to allocating MVCCStats on a sync.Pool. Since logAppend already has another pooled roachpb.Value with exactly the same lifetime, coalesce the allocation of both and put them in the same pool. This makes the cost of this change zero. Microbenchmark results: ``` // before BenchmarkLogStore_StoreEntries/bytes=1.0_KiB-24 837254 1270 ns/op 333 B/op 1 allocs/op // after BenchmarkLogStore_StoreEntries/bytes=1.0_KiB-24 1000000 1153 ns/op 157 B/op 0 allocs/op ``` Epic: none Release note: none
a176594
to
bf28d2e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice that we could reuse the pool.
return new(struct { | ||
roachpb.Value | ||
enginepb.MVCCStats | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: may as well give this type a name, but don't really care either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meh, I think that's one of the cases where it's somewhat beneficial to not introduce a type explicitly (so that there is zero encouragement to use it elsewhere). There is exactly one caller/user of this type, and it's tied to the pool, and the pool is tied to a single function (also a reason why I renamed the pool after the function's name).
Btw, see |
bors r=erikgrinaker |
Build succeeded: |
Before this commit,
logstore.logAppend
allocatedMVCCStats
on heap despite its lifetime being confined within this function's scope.This commit switches to allocating
MVCCStats
on async.Pool
. SincelogAppend
already has another pooledroachpb.Value
with exactly the same lifetime, coalesce the allocation of both and put them in the same pool. This makes the cost of this change zero.Microbenchmark results:
Part of #111561
Epic: none
Release note: none