Skip to content
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

storage: batch pebbleResults allocation #98718

Merged
merged 1 commit into from
Mar 16, 2023

Conversation

jbowens
Copy link
Collaborator

@jbowens jbowens commented Mar 15, 2023

Embed a pebbleResults struct on the pebbleMVCCScanner to avoid an allocation.

                                                                     │  23.1.txt   │           23.1-wip.txt            │
                                                                     │   sec/op    │   sec/op     vs base              │
MVCCGet_Pebble/batch=true/versions=100/valueSize=8/numRangeKeys=0-24   109.3µ ± 1%   105.2µ ± 3%  -3.73% (p=0.009 n=6)

                                                                     │   23.1.txt   │          23.1-wip.txt          │
                                                                     │     B/s      │      B/s       vs base         │
MVCCGet_Pebble/batch=true/versions=100/valueSize=8/numRangeKeys=0-24   68.36Ki ± 0%   78.12Ki ± 12%  ~ (p=0.061 n=6)

                                                                     │  23.1.txt   │            23.1-wip.txt            │
                                                                     │    B/op     │    B/op      vs base               │
MVCCGet_Pebble/batch=true/versions=100/valueSize=8/numRangeKeys=0-24   354.0 ± 22%   228.5 ± 28%  -35.45% (p=0.002 n=6)

                                                                     │  23.1.txt  │           23.1-wip.txt            │
                                                                     │ allocs/op  │ allocs/op   vs base               │
MVCCGet_Pebble/batch=true/versions=100/valueSize=8/numRangeKeys=0-24   3.000 ± 0%   2.000 ± 0%  -33.33% (p=0.002 n=6)

Informs #96960.
Epic: None
Release note: None

@jbowens jbowens requested a review from yuzefovich March 15, 2023 21:59
@jbowens jbowens requested a review from a team as a code owner March 15, 2023 21:59
@jbowens jbowens requested a review from sumeerbhola March 15, 2023 21:59
@blathers-crl
Copy link

blathers-crl bot commented Mar 15, 2023

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator

@sumeerbhola sumeerbhola left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 3 of 3 files at r1, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @jbowens and @yuzefovich)


pkg/storage/mvcc.go line 3713 at r1 (raw file):

		failOnMoreRecent: opts.FailOnMoreRecent,
		keyBuf:           mvccScanner.keyBuf,
		alloc:            mvccScanner.alloc,

is this alloc: mvccScanner.alloc, necessary given that we are not reusing anything contained in pebbleResults?
Or is it for a future where we may add other things to alloc that we want to reuse?


pkg/storage/pebble_mvcc_scanner.go line 481 at r1 (raw file):

		// Embedding the pebbleResults within the pebbleMVCCScanner avoids an
		// extra allocation, at the cost of higher allocated bytes when we use a
		// different implementation of the results interface.

We are only trying to avoid the allocation of this wrapper pebbleResults object, yes?
I assume we can't reuse the buffers that pebbleResults points to, since we are returning references to those byte slices to the callers that call into mvcc.go.
I would prefer if we cleared pebbleResults in pebbleMVCCScanner.release to avoid delaying gc of those byte slices and to ensure that there is no accidental reuse (the latter is just defensive given you already have *results = pebbleResults{} on the allocation path).

@jbowens jbowens force-pushed the mvccscanner-pebbleresults branch from 7965e26 to d8515b1 Compare March 16, 2023 14:41
Copy link
Collaborator 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: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @sumeerbhola and @yuzefovich)


pkg/storage/mvcc.go line 3713 at r1 (raw file):

Previously, sumeerbhola wrote…

is this alloc: mvccScanner.alloc, necessary given that we are not reusing anything contained in pebbleResults?
Or is it for a future where we may add other things to alloc that we want to reuse?

it's because the caller passes in a results. If results points to pebbleMVCCScanner.alloc.pebbleResults, this struct initialization will clear any initialization of pebbleMVCCScanner.alloc.pebbleResults already performed by the caller.


pkg/storage/pebble_mvcc_scanner.go line 481 at r1 (raw file):

We are only trying to avoid the allocation of this wrapper pebbleResults object, yes?

Yeah

I would prefer if we cleared pebbleResults in pebbleMVCCScanner.release to avoid delaying gc of those byte slices and to ensure that there is no accidental reuse (the latter is just defensive given you already have *results = pebbleResults{} on the allocation path).

We currently do clear all of the pebbleMVCCScanner struct, including pebbleResults on release. I added a comment there specifically calling out the importance of clearing alloc.pebbleResults.

Copy link
Collaborator 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.

bors r=sumeerbhola

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @sumeerbhola and @yuzefovich)

@craig
Copy link
Contributor

craig bot commented Mar 16, 2023

Build failed (retrying...):

Copy link
Collaborator

@sumeerbhola sumeerbhola left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r2.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @jbowens and @yuzefovich)


pkg/storage/mvcc.go line 3713 at r1 (raw file):

Previously, jbowens (Jackson Owens) wrote…

it's because the caller passes in a results. If results points to pebbleMVCCScanner.alloc.pebbleResults, this struct initialization will clear any initialization of pebbleMVCCScanner.alloc.pebbleResults already performed by the caller.

This is subtle. Could use a code comment.

@craig
Copy link
Contributor

craig bot commented Mar 16, 2023

Build failed (retrying...):

@jbowens
Copy link
Collaborator Author

jbowens commented Mar 16, 2023

bors cancel

@craig
Copy link
Contributor

craig bot commented Mar 16, 2023

Canceled.

Embed a `pebbleResults` struct on the `pebbleMVCCScanner` to avoid an
allocation.

```
                                                                     │  23.1.txt   │           23.1-wip.txt            │
                                                                     │   sec/op    │   sec/op     vs base              │
MVCCGet_Pebble/batch=true/versions=100/valueSize=8/numRangeKeys=0-24   109.3µ ± 1%   105.2µ ± 3%  -3.73% (p=0.009 n=6)

                                                                     │   23.1.txt   │          23.1-wip.txt          │
                                                                     │     B/s      │      B/s       vs base         │
MVCCGet_Pebble/batch=true/versions=100/valueSize=8/numRangeKeys=0-24   68.36Ki ± 0%   78.12Ki ± 12%  ~ (p=0.061 n=6)

                                                                     │  23.1.txt   │            23.1-wip.txt            │
                                                                     │    B/op     │    B/op      vs base               │
MVCCGet_Pebble/batch=true/versions=100/valueSize=8/numRangeKeys=0-24   354.0 ± 22%   228.5 ± 28%  -35.45% (p=0.002 n=6)

                                                                     │  23.1.txt  │           23.1-wip.txt            │
                                                                     │ allocs/op  │ allocs/op   vs base               │
MVCCGet_Pebble/batch=true/versions=100/valueSize=8/numRangeKeys=0-24   3.000 ± 0%   2.000 ± 0%  -33.33% (p=0.002 n=6)
```

Informs cockroachdb#96960.
Epic: None
Release note: None
@jbowens jbowens force-pushed the mvccscanner-pebbleresults branch from d8515b1 to d93a851 Compare March 16, 2023 17:16
Copy link
Collaborator 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.

bors r=sumeerbhola

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @sumeerbhola and @yuzefovich)


pkg/storage/mvcc.go line 3713 at r1 (raw file):

Previously, sumeerbhola wrote…

This is subtle. Could use a code comment.

Done.

Copy link
Member

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

:lgtm: Thanks!

Reviewed 1 of 3 files at r1, 1 of 1 files at r2, 1 of 1 files at r3, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (and 1 stale) (waiting on @sumeerbhola)

@craig
Copy link
Contributor

craig bot commented Mar 16, 2023

Build succeeded:

@craig craig bot merged commit 82fd797 into cockroachdb:master Mar 16, 2023
@jbowens jbowens deleted the mvccscanner-pebbleresults branch March 16, 2023 18:16
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.

4 participants