Skip to content

Commit 489b133

Browse files
committed
colblk: remove BlockDecoder allocation
``` goos: darwin goarch: arm64 pkg: github.com/cockroachdb/pebble/sstable/colblk cpu: Apple M1 Pro │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ DataBlockDecoderInit-10 94.53n ± 0% 82.12n ± 0% -13.13% (p=0.000 n=25) │ old.txt │ new.txt │ │ B/op │ B/op vs base │ DataBlockDecoderInit-10 48.00 ± 0% 0.00 ± 0% -100.00% (p=0.000 n=25) │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ DataBlockDecoderInit-10 1.000 ± 0% 0.000 ± 0% -100.00% (p=0.000 n=25) ``` Fix #5339.
1 parent 5c08fa3 commit 489b133

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

cockroachkvs/cockroachkvs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ var KeySchema = colblk.KeySchema{
498498
NewKeyWriter: func() colblk.KeyWriter {
499499
return makeCockroachKeyWriter()
500500
},
501-
InitKeySeekerMetadata: func(meta *colblk.KeySeekerMetadata, d *colblk.DataBlockDecoder, bd *colblk.BlockDecoder) {
501+
InitKeySeekerMetadata: func(meta *colblk.KeySeekerMetadata, d *colblk.DataBlockDecoder, bd colblk.BlockDecoder) {
502502
ks := (*cockroachKeySeeker)(unsafe.Pointer(meta))
503503
ks.init(d, bd)
504504
},
@@ -747,7 +747,7 @@ 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) {
750+
func (ks *cockroachKeySeeker) init(d *colblk.DataBlockDecoder, bd colblk.BlockDecoder) {
751751
ks.roachKeys = bd.PrefixBytes(cockroachColRoachKey)
752752
ks.roachKeyChanged = d.PrefixChanged()
753753
ks.mvccWallTimes = bd.Uints(cockroachColMVCCWallTime)

cockroachkvs/cockroachkvs_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func TestKeySchema_KeySeeker(t *testing.T) {
204204
var buf bytes.Buffer
205205
var enc colblk.DataBlockEncoder
206206
var dec colblk.DataBlockDecoder
207-
var bd *colblk.BlockDecoder
207+
var bd colblk.BlockDecoder
208208
var ks colblk.KeySeeker
209209
var maxKeyLen int
210210
enc.Init(&KeySchema)

sstable/colblk/data_block.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type KeySchema struct {
4444
// InitKeySeekerMetadata initializes the provided KeySeekerMetadata. This
4545
// happens once when a block enters the block cache and can be used to save
4646
// computation in NewKeySeeker.
47-
InitKeySeekerMetadata func(meta *KeySeekerMetadata, d *DataBlockDecoder, bd *BlockDecoder)
47+
InitKeySeekerMetadata func(meta *KeySeekerMetadata, d *DataBlockDecoder, bd BlockDecoder)
4848

4949
// KeySeeker returns a KeySeeker using metadata that was previously
5050
// initialized with InitKeySeekerMetadata. The returned key seeker can be an
@@ -215,10 +215,10 @@ func DefaultKeySchema(comparer *base.Comparer, prefixBundleSize int) KeySchema {
215215
kw.suffixes.Init()
216216
return kw
217217
},
218-
InitKeySeekerMetadata: func(meta *KeySeekerMetadata, d *DataBlockDecoder, bd *BlockDecoder) {
218+
InitKeySeekerMetadata: func(meta *KeySeekerMetadata, d *DataBlockDecoder, bd BlockDecoder) {
219219
ks := (*defaultKeySeeker)(unsafe.Pointer(&meta[0]))
220220
ks.comparer = comparer
221-
ks.init(d, bd)
221+
ks.init(d, &bd)
222222
},
223223
KeySeeker: func(meta *KeySeekerMetadata) KeySeeker {
224224
ks := (*defaultKeySeeker)(unsafe.Pointer(&meta[0]))
@@ -892,7 +892,7 @@ func (d *DataBlockDecoder) PrefixChanged() Bitmap {
892892
}
893893

894894
// Init initializes the data block reader with the given serialized data block.
895-
func (d *DataBlockDecoder) Init(schema *KeySchema, data []byte) *BlockDecoder {
895+
func (d *DataBlockDecoder) Init(schema *KeySchema, data []byte) BlockDecoder {
896896
if uintptr(unsafe.Pointer(unsafe.SliceData(data)))&7 != 0 {
897897
panic("data buffer not 8-byte aligned")
898898
}
@@ -904,12 +904,12 @@ func (d *DataBlockDecoder) Init(schema *KeySchema, data []byte) *BlockDecoder {
904904
d.isValueExternal = bd.Bitmap(len(schema.ColumnTypes) + dataBlockColumnIsValueExternal)
905905
d.isObsolete = bd.Bitmap(len(schema.ColumnTypes) + dataBlockColumnIsObsolete)
906906
d.maximumKeyLength = binary.LittleEndian.Uint32(data[schema.HeaderSize:])
907-
return &bd
907+
return bd
908908
}
909909

910910
// Describe descirbes the binary format of the data block, assuming f.Offset()
911911
// is positioned at the beginning of the same data block described by d.
912-
func (d *DataBlockDecoder) Describe(f *binfmt.Formatter, tp treeprinter.Node, bd *BlockDecoder) {
912+
func (d *DataBlockDecoder) Describe(f *binfmt.Formatter, tp treeprinter.Node, bd BlockDecoder) {
913913
// Set the relative offset. When loaded into memory, the beginning of blocks
914914
// are aligned. Padding that ensures alignment is done relative to the
915915
// current offset. Setting the relative offset ensures that if we're
@@ -1051,7 +1051,7 @@ func (i *DataBlockIter) InitOnce(
10511051
// Init initializes the data block iterator, configuring it to read from the
10521052
// provided decoder.
10531053
func (i *DataBlockIter) Init(
1054-
d *DataBlockDecoder, bd *BlockDecoder, transforms blockiter.Transforms,
1054+
d *DataBlockDecoder, bd BlockDecoder, transforms blockiter.Transforms,
10551055
) error {
10561056
i.d = d
10571057
// Leave i.h unchanged.

sstable/colblk/data_block_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func TestDataBlock(t *testing.T) {
2929
var buf bytes.Buffer
3030
var w DataBlockEncoder
3131
var r DataBlockDecoder
32-
var bd *BlockDecoder
32+
var bd BlockDecoder
3333
var v DataBlockValidator
3434
var it DataBlockIter
3535
rw := NewDataBlockRewriter(&testKeysSchema, testkeys.Comparer.EnsureDefaults())

0 commit comments

Comments
 (0)