Skip to content

kv: avoid heap alloc of RangeAppliedState per Raft apply batch#84106

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
nvb:nvanbenschoten/raskAlloc
Jul 12, 2022
Merged

kv: avoid heap alloc of RangeAppliedState per Raft apply batch#84106
craig[bot] merged 1 commit intocockroachdb:masterfrom
nvb:nvanbenschoten/raskAlloc

Conversation

@nvb
Copy link
Copy Markdown
Contributor

@nvb nvb commented Jul 8, 2022

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)

@nvb nvb requested a review from erikgrinaker July 8, 2022 21:14
@nvb nvb requested a review from a team as a code owner July 8, 2022 21:14
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
Contributor

@erikgrinaker erikgrinaker left a comment

Choose a reason for hiding this comment

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

Nice find, thanks!

Reviewed 4 of 4 files at r1, all commit messages.
Reviewable status: :shipit: 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)
```
@nvb nvb force-pushed the nvanbenschoten/raskAlloc branch from 5809229 to a345d46 Compare July 12, 2022 03:09
Copy link
Copy Markdown
Contributor Author

@nvb nvb left a comment

Choose a reason for hiding this comment

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

TFTR!

bors r=erikgrinaker

Reviewable status: :shipit: 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 addAppliedStateKeyToBatch to avoid heap allocations."

Done.

@craig craig bot merged commit 571bfa3 into cockroachdb:master Jul 12, 2022
@craig
Copy link
Copy Markdown
Contributor

craig bot commented Jul 12, 2022

Build succeeded:

@nvb nvb deleted the nvanbenschoten/raskAlloc branch July 12, 2022 16:44
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