Commit e822649
committed
kv: pass BatchRequest by reference, not value
This commit switches the sender interface from:
```go
type Sender interface {
Send(context.Context, roachpb.BatchRequest) (*roachpb.BatchResponse, *roachpb.Error)
}
```
to
```go
type Sender interface {
Send(context.Context, *roachpb.BatchRequest) (*roachpb.BatchResponse, *roachpb.Error)
}
```
In doing so, the entire KV layer (client-side and server-side) switches from
passing `BatchRequest` objects by pointer instead of by value. These objects are
over 200 bytes in size and are passed to hundreds of functions throughout the KV
layer in service of a single request, so this is a dramatic reduction in memory
copies. Furthermore, these objects were often already escaping to the heap, so
this actually reduces heap allocations by being more deliberate about when we
heap allocate and when we perform a shallow clone.
\### Macro benchmarks
```
name old ops/s new ops/s delta
kv95/enc=false/nodes=3/cpu=32 120k ± 4% 122k ± 3% +2.28% (p=0.052 n=10+10)
name old avg(ms) new avg(ms) delta
kv95/enc=false/nodes=3/cpu=32 1.60 ± 0% 1.60 ± 0% ~ (all equal)
name old p99(ms) new p99(ms) delta
kv95/enc=false/nodes=3/cpu=32 7.79 ± 4% 7.60 ± 0% -2.44% (p=0.013 n=10+8)
```
This commit is based on #86957. Together, they have the following impact on macro
benchmark performance:
```
name old ops/s new ops/s delta
kv95/enc=false/nodes=3/cpu=32 109k ±10% 122k ± 3% +12.35% (p=0.000 n=10+10)
name old avg(ms) new avg(ms) delta
kv95/enc=false/nodes=3/cpu=32 1.79 ±12% 1.60 ± 0% -10.61% (p=0.000 n=10+8)
name old p99(ms) new p99(ms) delta
kv95/enc=false/nodes=3/cpu=32 8.53 ±17% 7.60 ± 0% -10.90% (p=0.000 n=10+8)
```
\### Micro benchmarks
```
name old time/op new time/op delta
KV/Scan/Native/rows=1-10 17.1µs ± 1% 16.5µs ± 2% -3.36% (p=0.000 n=8+10)
KV/Update/Native/rows=1-10 66.9µs ± 2% 65.2µs ± 2% -2.52% (p=0.000 n=9+10)
KV/Insert/Native/rows=1-10 42.1µs ± 3% 41.3µs ± 3% -1.95% (p=0.015 n=10+10)
KV/Delete/Native/rows=1-10 41.9µs ± 3% 41.2µs ± 2% -1.69% (p=0.035 n=10+10)
KV/Insert/SQL/rows=1-10 125µs ± 2% 126µs ± 6% ~ (p=0.631 n=10+10)
KV/Update/SQL/rows=1-10 171µs ± 4% 170µs ± 3% ~ (p=0.579 n=10+10)
KV/Delete/SQL/rows=1-10 138µs ± 4% 138µs ± 4% ~ (p=0.393 n=10+10)
KV/Scan/SQL/rows=1-10 94.4µs ± 4% 93.6µs ± 3% ~ (p=0.579 n=10+10)
name old alloc/op new alloc/op delta
KV/Update/Native/rows=1-10 22.3kB ± 0% 21.6kB ± 0% -2.83% (p=0.000 n=9+10)
KV/Insert/Native/rows=1-10 15.8kB ± 0% 15.5kB ± 0% -1.86% (p=0.000 n=9+10)
KV/Delete/Native/rows=1-10 15.5kB ± 1% 15.2kB ± 0% -1.83% (p=0.000 n=10+10)
KV/Update/SQL/rows=1-10 51.6kB ± 0% 51.0kB ± 0% -1.11% (p=0.000 n=10+8)
KV/Insert/SQL/rows=1-10 44.8kB ± 0% 44.4kB ± 0% -0.80% (p=0.000 n=10+9)
KV/Scan/Native/rows=1-10 7.57kB ± 0% 7.52kB ± 0% -0.70% (p=0.000 n=9+10)
KV/Delete/SQL/rows=1-10 51.6kB ± 0% 51.3kB ± 0% -0.54% (p=0.000 n=10+10)
KV/Scan/SQL/rows=1-10 24.3kB ± 0% 24.3kB ± 0% -0.14% (p=0.009 n=8+10)
name old allocs/op new allocs/op delta
KV/Update/Native/rows=1-10 182 ± 0% 181 ± 0% -0.89% (p=0.000 n=9+10)
KV/Delete/Native/rows=1-10 127 ± 0% 126 ± 0% -0.79% (p=0.000 n=10+10)
KV/Insert/Native/rows=1-10 128 ± 0% 127 ± 0% -0.78% (p=0.000 n=9+10)
KV/Update/SQL/rows=1-10 521 ± 0% 519 ± 0% -0.39% (p=0.000 n=10+8)
KV/Delete/SQL/rows=1-10 386 ± 0% 385 ± 0% -0.26% (p=0.000 n=8+8)
KV/Insert/SQL/rows=1-10 359 ± 0% 359 ± 0% -0.22% (p=0.009 n=10+10)
KV/Scan/Native/rows=1-10 55.0 ± 0% 55.0 ± 0% ~ (all equal)
KV/Scan/SQL/rows=1-10 281 ± 0% 281 ± 0% ~ (all equal)
```
Release justification: None. Don't merge until after the branch cut.1 parent 3dd5e68 commit e822649
127 files changed
Lines changed: 870 additions & 837 deletions
File tree
- pkg
- ccl
- backupccl
- changefeedccl
- kvccl/kvfollowerreadsccl
- streamingccl/streamingest
- cli
- internal/client/requestbatcher
- jobs
- kv
- bulk
- kvclient
- kvcoord
- kvstreamer
- rangefeed/rangefeedcache
- kvprober
- kvserver
- batcheval
- intentresolver
- kvserverbase
- protectedts/ptcache
- txnrecovery
- txnwait
- roachpb
- rpc
- server
- systemconfigwatcher/systemconfigwatchertest
- sql
- backfill
- catalog
- descs
- lease
- gcjob_test
- importer
- rowexec
- row
- sem
- builtins
- eval
- sqlliveness/slstorage
- sqlstats/persistedsqlstats
- stats
- stmtdiagnostics
- testutils
- jobutils
- kvclientutils
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6170 | 6170 | | |
6171 | 6171 | | |
6172 | 6172 | | |
6173 | | - | |
| 6173 | + | |
6174 | 6174 | | |
6175 | 6175 | | |
6176 | 6176 | | |
| |||
6298 | 6298 | | |
6299 | 6299 | | |
6300 | 6300 | | |
6301 | | - | |
| 6301 | + | |
6302 | 6302 | | |
6303 | 6303 | | |
6304 | 6304 | | |
| |||
6316 | 6316 | | |
6317 | 6317 | | |
6318 | 6318 | | |
6319 | | - | |
| 6319 | + | |
6320 | 6320 | | |
6321 | 6321 | | |
6322 | 6322 | | |
| |||
7156 | 7156 | | |
7157 | 7157 | | |
7158 | 7158 | | |
7159 | | - | |
| 7159 | + | |
7160 | 7160 | | |
7161 | 7161 | | |
7162 | 7162 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4830 | 4830 | | |
4831 | 4831 | | |
4832 | 4832 | | |
4833 | | - | |
| 4833 | + | |
4834 | 4834 | | |
4835 | 4835 | | |
4836 | 4836 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
137 | | - | |
| 137 | + | |
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | | - | |
112 | | - | |
| 111 | + | |
| 112 | + | |
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
117 | | - | |
| 117 | + | |
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
121 | | - | |
| 121 | + | |
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
129 | | - | |
| 129 | + | |
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| |||
441 | 441 | | |
442 | 442 | | |
443 | 443 | | |
| 444 | + | |
444 | 445 | | |
445 | 446 | | |
446 | 447 | | |
447 | 448 | | |
448 | 449 | | |
| 450 | + | |
449 | 451 | | |
450 | 452 | | |
451 | 453 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
154 | | - | |
| 154 | + | |
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
264 | 264 | | |
265 | 265 | | |
266 | 266 | | |
267 | | - | |
| 267 | + | |
268 | 268 | | |
269 | 269 | | |
270 | 270 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
526 | 526 | | |
527 | 527 | | |
528 | 528 | | |
529 | | - | |
530 | | - | |
| 529 | + | |
| 530 | + | |
531 | 531 | | |
532 | 532 | | |
533 | 533 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| |||
501 | 501 | | |
502 | 502 | | |
503 | 503 | | |
504 | | - | |
| 504 | + | |
505 | 505 | | |
506 | 506 | | |
507 | 507 | | |
| |||
513 | 513 | | |
514 | 514 | | |
515 | 515 | | |
516 | | - | |
| 516 | + | |
517 | 517 | | |
518 | 518 | | |
519 | 519 | | |
| |||
525 | 525 | | |
526 | 526 | | |
527 | 527 | | |
528 | | - | |
| 528 | + | |
529 | 529 | | |
530 | 530 | | |
531 | 531 | | |
| |||
536 | 536 | | |
537 | 537 | | |
538 | 538 | | |
539 | | - | |
| 539 | + | |
540 | 540 | | |
541 | 541 | | |
542 | 542 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2728 | 2728 | | |
2729 | 2729 | | |
2730 | 2730 | | |
2731 | | - | |
| 2731 | + | |
2732 | 2732 | | |
2733 | 2733 | | |
2734 | 2734 | | |
| |||
0 commit comments