-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
3dd5e68
commit e822649
Showing
127 changed files
with
870 additions
and
837 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.