kv: avoid heap alloc of RangeAppliedState per Raft apply batch#84106
Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom Jul 12, 2022
Merged
kv: avoid heap alloc of RangeAppliedState per Raft apply batch#84106craig[bot] merged 1 commit intocockroachdb:masterfrom
craig[bot] merged 1 commit intocockroachdb:masterfrom
Conversation
Member
erikgrinaker
approved these changes
Jul 11, 2022
Contributor
erikgrinaker
left a comment
There was a problem hiding this comment.
Nice find, thanks!
Reviewed 4 of 4 files at r1, all commit messages.
Reviewable status:complete! 0 of 0 LGTMs obtained (waiting on @nvanbenschoten)
pkg/kv/kvserver/replica_application_state_machine.go line 439 at r1 (raw file):
start time.Time // Avoid heap allocations.
Would be good to elaborate on this slightly, i.e. "Reused by addAppliedStateKeyToBatch to avoid heap allocations."
This commit hangs a `RangeAppliedState` struct off of `replicaAppBatch` so that a Raft application batch can avoid a heap allocation during its call to `addAppliedStateKeyToBatch`. ``` name old time/op new time/op delta KV/Insert/Native/rows=1-10 46.3µs ± 7% 46.3µs ± 4% ~ (p=0.553 n=19+18) KV/Insert/SQL/rows=1-10 141µs ±18% 133µs ± 7% ~ (p=0.075 n=19+18) name old alloc/op new alloc/op delta KV/Insert/Native/rows=1-10 15.6kB ± 2% 15.4kB ± 1% -1.46% (p=0.000 n=20+20) KV/Insert/SQL/rows=1-10 43.0kB ± 0% 42.9kB ± 0% -0.43% (p=0.000 n=19+19) name old allocs/op new allocs/op delta KV/Insert/Native/rows=1-10 131 ± 0% 130 ± 0% -0.76% (p=0.000 n=19+20) KV/Insert/SQL/rows=1-10 350 ± 0% 349 ± 0% -0.29% (p=0.000 n=16+19) ```
5809229 to
a345d46
Compare
nvb
commented
Jul 12, 2022
Contributor
Author
nvb
left a comment
There was a problem hiding this comment.
TFTR!
bors r=erikgrinaker
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @erikgrinaker)
pkg/kv/kvserver/replica_application_state_machine.go line 439 at r1 (raw file):
Previously, erikgrinaker (Erik Grinaker) wrote…
Would be good to elaborate on this slightly, i.e. "Reused by
addAppliedStateKeyToBatchto avoid heap allocations."
Done.
Contributor
|
Build succeeded: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit hangs a
RangeAppliedStatestruct off ofreplicaAppBatchso that a Raft application batch can avoid a heap allocation during its
call to
addAppliedStateKeyToBatch.