-
Notifications
You must be signed in to change notification settings - Fork 478
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
*: use Equal for more efficient equality comparisons #1918
Conversation
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.
LGTM at high level, thanks!
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.
Reviewed 14 of 14 files at r1, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @jbowens)
internal/keyspan/defragment.go
line 24 at r1 (raw file):
// ShouldDefragment takes two abutting spans and returns whether the two // spans should be combined into a single, defragmented Span. ShouldDefragment(comparer *base.Comparer, left, right *Span) bool
is the change to pointer indirection in this file not a performance regression?
Use base.Equal for equality comparisons in more places. Equal(a,b) is faster than Compare(a,b)==0. Additionally, embed the Comparer directly into the Iterator struct for better cache locality and to avoid the additional pointer indirection. Informs cockroachdb#1819. Informs cockroachdb/cockroach#82559. ``` name old time/op new time/op delta MVCCScan_Pebble/rows=1/versions=1/valueSize=64/numRangeKeys=0-24 6.80µs ± 1% 6.72µs ± 2% ~ (p=0.165 n=5+10) MVCCScan_Pebble/rows=1/versions=1/valueSize=64/numRangeKeys=1-24 14.1µs ± 1% 14.0µs ± 2% ~ (p=0.107 n=5+10) MVCCScan_Pebble/rows=1/versions=1/valueSize=64/numRangeKeys=100-24 154µs ± 2% 152µs ± 2% ~ (p=0.075 n=5+10) MVCCScan_Pebble/rows=1/versions=2/valueSize=64/numRangeKeys=0-24 7.16µs ± 2% 7.10µs ± 1% ~ (p=0.147 n=5+9) MVCCScan_Pebble/rows=1/versions=2/valueSize=64/numRangeKeys=1-24 15.0µs ± 1% 14.9µs ± 1% -0.94% (p=0.007 n=5+9) MVCCScan_Pebble/rows=1/versions=2/valueSize=64/numRangeKeys=100-24 155µs ± 1% 155µs ± 1% ~ (p=0.513 n=5+10) MVCCScan_Pebble/rows=1/versions=10/valueSize=64/numRangeKeys=0-24 9.15µs ± 2% 8.91µs ± 0% -2.61% (p=0.003 n=5+7) MVCCScan_Pebble/rows=1/versions=10/valueSize=64/numRangeKeys=1-24 18.2µs ± 2% 18.1µs ± 1% ~ (p=0.518 n=5+9) MVCCScan_Pebble/rows=1/versions=10/valueSize=64/numRangeKeys=100-24 147µs ± 4% 145µs ± 2% ~ (p=0.129 n=5+10) MVCCScan_Pebble/rows=1/versions=100/valueSize=64/numRangeKeys=0-24 18.1µs ± 2% 17.7µs ± 1% -1.98% (p=0.013 n=5+10) MVCCScan_Pebble/rows=1/versions=100/valueSize=64/numRangeKeys=1-24 27.5µs ± 1% 27.2µs ± 2% ~ (p=0.206 n=5+10) MVCCScan_Pebble/rows=1/versions=100/valueSize=64/numRangeKeys=100-24 112µs ± 4% 109µs ± 1% ~ (p=0.075 n=5+10) MVCCScan_Pebble/rows=10/versions=1/valueSize=64/numRangeKeys=0-24 12.1µs ± 2% 11.8µs ± 2% -3.00% (p=0.003 n=5+10) MVCCScan_Pebble/rows=10/versions=1/valueSize=64/numRangeKeys=1-24 21.5µs ± 1% 20.8µs ± 1% -3.02% (p=0.001 n=5+9) MVCCScan_Pebble/rows=10/versions=1/valueSize=64/numRangeKeys=100-24 105µs ± 3% 102µs ± 1% -2.73% (p=0.013 n=5+10) MVCCScan_Pebble/rows=10/versions=2/valueSize=64/numRangeKeys=0-24 13.8µs ± 2% 13.4µs ± 4% -2.89% (p=0.013 n=5+10) MVCCScan_Pebble/rows=10/versions=2/valueSize=64/numRangeKeys=1-24 24.3µs ± 2% 23.8µs ± 2% ~ (p=0.075 n=5+10) MVCCScan_Pebble/rows=10/versions=2/valueSize=64/numRangeKeys=100-24 109µs ± 2% 105µs ± 2% -3.43% (p=0.005 n=5+10) MVCCScan_Pebble/rows=10/versions=10/valueSize=64/numRangeKeys=0-24 25.0µs ± 1% 24.2µs ± 3% -3.27% (p=0.001 n=5+10) MVCCScan_Pebble/rows=10/versions=10/valueSize=64/numRangeKeys=1-24 42.6µs ± 2% 42.0µs ± 2% ~ (p=0.055 n=5+10) MVCCScan_Pebble/rows=10/versions=10/valueSize=64/numRangeKeys=100-24 129µs ± 3% 127µs ± 2% -1.61% (p=0.040 n=5+10) MVCCScan_Pebble/rows=10/versions=100/valueSize=64/numRangeKeys=0-24 63.2µs ± 1% 61.7µs ± 1% -2.30% (p=0.001 n=5+10) MVCCScan_Pebble/rows=10/versions=100/valueSize=64/numRangeKeys=1-24 83.4µs ± 1% 81.6µs ± 1% -2.16% (p=0.003 n=5+10) MVCCScan_Pebble/rows=10/versions=100/valueSize=64/numRangeKeys=100-24 178µs ± 2% 173µs ± 1% -2.46% (p=0.001 n=5+10) MVCCScan_Pebble/rows=100/versions=1/valueSize=64/numRangeKeys=0-24 47.4µs ± 2% 46.0µs ± 1% -2.89% (p=0.001 n=5+10) MVCCScan_Pebble/rows=100/versions=1/valueSize=64/numRangeKeys=1-24 74.2µs ± 1% 71.2µs ± 2% -4.06% (p=0.001 n=5+10) MVCCScan_Pebble/rows=100/versions=1/valueSize=64/numRangeKeys=100-24 173µs ± 1% 170µs ± 3% ~ (p=0.055 n=5+10) MVCCScan_Pebble/rows=100/versions=2/valueSize=64/numRangeKeys=0-24 60.8µs ± 2% 59.1µs ± 2% -2.82% (p=0.001 n=5+10) MVCCScan_Pebble/rows=100/versions=2/valueSize=64/numRangeKeys=1-24 95.8µs ± 1% 94.2µs ± 2% -1.75% (p=0.019 n=5+10) MVCCScan_Pebble/rows=100/versions=2/valueSize=64/numRangeKeys=100-24 197µs ± 2% 193µs ± 2% -1.85% (p=0.019 n=5+10) MVCCScan_Pebble/rows=100/versions=10/valueSize=64/numRangeKeys=0-24 148µs ± 1% 145µs ± 1% -1.66% (p=0.003 n=5+10) MVCCScan_Pebble/rows=100/versions=10/valueSize=64/numRangeKeys=1-24 247µs ± 1% 241µs ± 2% -2.32% (p=0.003 n=5+10) MVCCScan_Pebble/rows=100/versions=10/valueSize=64/numRangeKeys=100-24 390µs ± 2% 382µs ± 2% -1.95% (p=0.028 n=5+10) MVCCScan_Pebble/rows=100/versions=100/valueSize=64/numRangeKeys=0-24 441µs ± 2% 437µs ± 1% ~ (p=0.222 n=5+8) MVCCScan_Pebble/rows=100/versions=100/valueSize=64/numRangeKeys=1-24 558µs ± 1% 547µs ± 1% -2.01% (p=0.004 n=4+10) MVCCScan_Pebble/rows=100/versions=100/valueSize=64/numRangeKeys=100-24 790µs ± 2% 774µs ± 2% -1.93% (p=0.008 n=5+10) MVCCScan_Pebble/rows=1000/versions=1/valueSize=64/numRangeKeys=0-24 350µs ± 1% 346µs ± 1% ~ (p=0.075 n=5+10) MVCCScan_Pebble/rows=1000/versions=1/valueSize=64/numRangeKeys=1-24 539µs ± 1% 534µs ± 2% ~ (p=0.206 n=5+10) MVCCScan_Pebble/rows=1000/versions=1/valueSize=64/numRangeKeys=100-24 759µs ± 1% 747µs ± 1% -1.61% (p=0.008 n=5+10) MVCCScan_Pebble/rows=1000/versions=2/valueSize=64/numRangeKeys=0-24 472µs ± 0% 466µs ± 0% -1.12% (p=0.003 n=4+9) MVCCScan_Pebble/rows=1000/versions=2/valueSize=64/numRangeKeys=1-24 755µs ± 1% 740µs ± 1% -2.03% (p=0.001 n=5+10) MVCCScan_Pebble/rows=1000/versions=2/valueSize=64/numRangeKeys=100-24 1.02ms ± 3% 0.96ms ± 2% -5.05% (p=0.001 n=5+10) MVCCScan_Pebble/rows=1000/versions=10/valueSize=64/numRangeKeys=0-24 1.29ms ± 1% 1.28ms ± 1% -1.42% (p=0.005 n=5+10) MVCCScan_Pebble/rows=1000/versions=10/valueSize=64/numRangeKeys=1-24 2.19ms ± 1% 2.13ms ± 1% -2.64% (p=0.001 n=5+10) MVCCScan_Pebble/rows=1000/versions=10/valueSize=64/numRangeKeys=100-24 2.82ms ± 2% 2.77ms ± 2% ~ (p=0.129 n=5+10) MVCCScan_Pebble/rows=1000/versions=100/valueSize=64/numRangeKeys=0-24 4.11ms ± 1% 4.08ms ± 2% ~ (p=0.859 n=5+10) MVCCScan_Pebble/rows=1000/versions=100/valueSize=64/numRangeKeys=1-24 5.17ms ± 2% 5.08ms ± 2% ~ (p=0.055 n=5+10) MVCCScan_Pebble/rows=1000/versions=100/valueSize=64/numRangeKeys=100-24 6.69ms ± 2% 6.61ms ± 4% ~ (p=0.206 n=5+10) ```
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.
tftrs!
Reviewable status: 10 of 14 files reviewed, 1 unresolved discussion (waiting on @sumeerbhola)
internal/keyspan/defragment.go
line 24 at r1 (raw file):
Previously, sumeerbhola wrote…
is the change to pointer indirection in this file not a performance regression?
it doesn't seem to be a measurable one, but I removed the indirection just in case.
Use base.Equal for equality comparisons in more places. Equal(a,b) is faster
than Compare(a,b)==0. Additionally, embed the Comparer directly into the
Iterator struct for better cache locality and to avoid the additional pointer
indirection.
Informs #1819.
Informs cockroachdb/cockroach#82559.