Skip to content

Commit 6e9ddf2

Browse files
committed
cockroachkvs: avoid cockroachKeysSeeker.init allocation
The change in #5345 prevented BlockDecoder from escaping to the heap when using the testkeys.KeySchema, but with the cockroachkvs.KeySchema the key seeker init func's local BlockDecoder still escaped. This commit updates the key seeker to call colblk.DecodeColumn directly, which is enough for the Go compiler to avoid moving the arg to the heap. ``` goos: darwin goarch: arm64 pkg: github.com/cockroachdb/pebble/cockroachkvs cpu: Apple M1 Pro │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ InitDataBlockMetadata-10 135.5n ± 1% 110.8n ± 0% -18.20% (p=0.002 n=6) │ old.txt │ new.txt │ │ B/op │ B/op vs base │ InitDataBlockMetadata-10 48.00 ± 0% 0.00 ± 0% -100.00% (p=0.002 n=6) │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ InitDataBlockMetadata-10 1.000 ± 0% 0.000 ± 0% -100.00% (p=0.002 n=6) ```
1 parent f3afdb6 commit 6e9ddf2

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

cockroachkvs/cockroachkvs.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -747,12 +747,20 @@ var _ uint = colblk.KeySeekerMetadataSize - uint(unsafe.Sizeof(cockroachKeySeeke
747747

748748
var _ colblk.KeySeeker = (*cockroachKeySeeker)(nil)
749749

750-
func (ks *cockroachKeySeeker) init(d *colblk.DataBlockDecoder, bd colblk.BlockDecoder) {
751-
ks.roachKeys = bd.PrefixBytes(cockroachColRoachKey)
750+
func (ks *cockroachKeySeeker) init(
751+
d *colblk.DataBlockDecoder,
752+
//gcassert:noescape
753+
bd colblk.BlockDecoder,
754+
) {
755+
// Note that we call DecodeColumn directly rather than using the
756+
// BlockDecoder's type-specific convenience methods (e.g. PrefixBytes,
757+
// Uints, etc) to avoid bd from escaping to the heap.
758+
rows := int(bd.Rows())
759+
ks.roachKeys = colblk.DecodeColumn(&bd, cockroachColRoachKey, rows, colblk.DataTypePrefixBytes, colblk.DecodePrefixBytes)
752760
ks.roachKeyChanged = d.PrefixChanged()
753-
ks.mvccWallTimes = bd.Uints(cockroachColMVCCWallTime)
754-
ks.mvccLogical = bd.Uints(cockroachColMVCCLogical)
755-
ks.untypedVersions = bd.RawBytes(cockroachColUntypedVersion)
761+
ks.mvccWallTimes = colblk.DecodeColumn(&bd, cockroachColMVCCWallTime, rows, colblk.DataTypeUint, colblk.DecodeUnsafeUints)
762+
ks.mvccLogical = colblk.DecodeColumn(&bd, cockroachColMVCCLogical, rows, colblk.DataTypeUint, colblk.DecodeUnsafeUints)
763+
ks.untypedVersions = colblk.DecodeColumn(&bd, cockroachColUntypedVersion, rows, colblk.DataTypeBytes, colblk.DecodeRawBytes)
756764
header := bd.Header()
757765
header = header[:len(header)-colblk.DataBlockCustomHeaderSize]
758766
if len(header) != 1 {

0 commit comments

Comments
 (0)