Skip to content

*: pass keyspan.Spans by pointer not value#1748

Merged
jbowens merged 1 commit intocockroachdb:masterfrom
jbowens:ptr-span
Jun 9, 2022
Merged

*: pass keyspan.Spans by pointer not value#1748
jbowens merged 1 commit intocockroachdb:masterfrom
jbowens:ptr-span

Conversation

@jbowens
Copy link
Copy Markdown
Contributor

@jbowens jbowens commented Jun 9, 2022

The first four commits are from #1743 and the fifth is from #1747, and they
should be reviewed in their respective PRs.


Previously the keyspan.Span type used to represent range deletions and range
keys was passed primarily by value, including through the FragmentIterator
interface. This was convenient when transforming spans (eg, truncating bounds),
but passing them by pointer is enough of a performance win to be worthwhile.

Informs cockroachdb/cockroach#82559.

name                                    old time/op    new time/op    delta
IteratorSeekNoRangeKeys/batch=false-10    4.28µs ± 1%    2.90µs ± 4%  -32.27%  (p=0.000 n=19+20)
IteratorSeekNoRangeKeys/batch=true-10     8.78µs ± 1%    5.37µs ± 1%  -38.86%  (p=0.000 n=20+20)

name                                    old alloc/op   new alloc/op   delta
IteratorSeekNoRangeKeys/batch=false-10     16.0B ± 0%     16.0B ± 0%     ~     (all equal)
IteratorSeekNoRangeKeys/batch=true-10       192B ± 0%      128B ± 0%  -33.33%  (p=0.000 n=20+20)

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@jbowens jbowens marked this pull request as draft June 9, 2022 01:22
@jbowens
Copy link
Copy Markdown
Contributor Author

jbowens commented Jun 9, 2022

Looks like I still have an interleaving iter invariant violation to work through.

@jbowens jbowens marked this pull request as ready for review June 9, 2022 01:54
Copy link
Copy Markdown
Contributor

@nicktrav nicktrav left a comment

Choose a reason for hiding this comment

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

Review was fairly mechanical, but :lgtm:!

Still have the other reviews sitting in my inbox 😅

Reviewed 1 of 1 files at r1, 4 of 11 files at r5, 50 of 50 files at r6, 1 of 1 files at r7, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @jbowens)


internal/keyspan/defragment.go line 438 at r6 (raw file):

	}
	if i.iterSpan == nil {
		// tktk: set i.currValid or something?

Leftovers?

@jbowens jbowens force-pushed the ptr-span branch 2 times, most recently from 16f18f3 to b576609 Compare June 9, 2022 02:14
Copy link
Copy Markdown
Contributor

@nicktrav nicktrav left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 3 files at r8, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @jbowens)

Previously the keyspan.Span type used to represent range deletions and range
keys was passed primarily by value, including through the FragmentIterator
interface. This was convenient when transforming spans (eg, truncating bounds),
but passing them by pointer is enough of a performance win to be worthwhile.

Informs cockroachdb/cockroach#82559.

```
name                                    old time/op    new time/op    delta
IteratorSeekNoRangeKeys/batch=false-10    4.28µs ± 1%    2.90µs ± 4%  -32.27%  (p=0.000 n=19+20)
IteratorSeekNoRangeKeys/batch=true-10     8.78µs ± 1%    5.37µs ± 1%  -38.86%  (p=0.000 n=20+20)

name                                    old alloc/op   new alloc/op   delta
IteratorSeekNoRangeKeys/batch=false-10     16.0B ± 0%     16.0B ± 0%     ~     (all equal)
IteratorSeekNoRangeKeys/batch=true-10       192B ± 0%      128B ± 0%  -33.33%  (p=0.000 n=20+20)
```
Copy link
Copy Markdown
Contributor Author

@jbowens jbowens left a comment

Choose a reason for hiding this comment

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

TFTR!

Reviewable status: 45 of 55 files reviewed, all discussions resolved (waiting on @nicktrav)

@jbowens jbowens merged commit 67f2653 into cockroachdb:master Jun 9, 2022
@jbowens jbowens deleted the ptr-span branch June 9, 2022 17:53
jbowens added a commit to jbowens/pebble that referenced this pull request Jul 29, 2022
… seeks

The defragmenting iterator avoids defragmenting empty spans, because the empty
span fragments are not observable by the user. However on seeks, it would still
pay the cost of buffering the empty span and stepping the iterator both
directions.

This was a regression added in cockroachdb#1748, and hidden among that change's own
performance wins. Previously, we used `Span.Empty()` in the defragmenting
iterator to detect both of the two cases: a span doesn't exist, or a span
exists but is empty. Now that nonexistent spans are surfaced as `nil`s, these
cases must handled separately.

```
name                                    old time/op    new time/op    delta
IteratorSeekNoRangeKeys/batch=false-10    2.58µs ± 1%    2.49µs ± 1%   -3.49%  (p=0.000 n=10+10)
IteratorSeekNoRangeKeys/batch=true-10     4.87µs ± 1%    4.02µs ± 1%  -17.44%  (p=0.000 n=10+10)

name                                    old alloc/op   new alloc/op   delta
IteratorSeekNoRangeKeys/batch=false-10     80.0B ± 0%     80.0B ± 0%     ~     (all equal)
IteratorSeekNoRangeKeys/batch=true-10       160B ± 0%      160B ± 0%     ~     (all equal)

name                                    old allocs/op  new allocs/op  delta
IteratorSeekNoRangeKeys/batch=false-10      2.00 ± 0%      2.00 ± 0%     ~     (all equal)
IteratorSeekNoRangeKeys/batch=true-10       3.00 ± 0%      3.00 ± 0%     ~     (all equal)
```
jbowens added a commit that referenced this pull request Aug 2, 2022
… seeks

The defragmenting iterator avoids defragmenting empty spans, because the empty
span fragments are not observable by the user. However on seeks, it would still
pay the cost of buffering the empty span and stepping the iterator both
directions.

This was a regression added in #1748, and hidden among that change's own
performance wins. Previously, we used `Span.Empty()` in the defragmenting
iterator to detect both of the two cases: a span doesn't exist, or a span
exists but is empty. Now that nonexistent spans are surfaced as `nil`s, these
cases must handled separately.

```
name                                    old time/op    new time/op    delta
IteratorSeekNoRangeKeys/batch=false-10    2.58µs ± 1%    2.49µs ± 1%   -3.49%  (p=0.000 n=10+10)
IteratorSeekNoRangeKeys/batch=true-10     4.87µs ± 1%    4.02µs ± 1%  -17.44%  (p=0.000 n=10+10)

name                                    old alloc/op   new alloc/op   delta
IteratorSeekNoRangeKeys/batch=false-10     80.0B ± 0%     80.0B ± 0%     ~     (all equal)
IteratorSeekNoRangeKeys/batch=true-10       160B ± 0%      160B ± 0%     ~     (all equal)

name                                    old allocs/op  new allocs/op  delta
IteratorSeekNoRangeKeys/batch=false-10      2.00 ± 0%      2.00 ± 0%     ~     (all equal)
IteratorSeekNoRangeKeys/batch=true-10       3.00 ± 0%      3.00 ± 0%     ~     (all equal)
```
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