Skip to content

Commit

Permalink
sstable: don't clone the last key for each data buffer
Browse files Browse the repository at this point in the history
This allocation is about 0.1% of all allocations in a sysbench
workload. Reuse a buffer instead.
  • Loading branch information
RaduBerinde committed Dec 12, 2024
1 parent 4949684 commit 924a669
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions sstable/colblk_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ type RawColumnWriter struct {
}
layout layoutWriter

lastKeyBuf []byte
separatorBuf []byte
tmp [blockHandleLikelyMaxLen]byte
previousUserKey invariants.Value[[]byte]
Expand Down Expand Up @@ -633,10 +634,11 @@ func (w *RawColumnWriter) maybeIncrementTombstoneDenseBlocks(uncompressedLen int
func (w *RawColumnWriter) enqueueDataBlock(
serializedBlock []byte, lastKey base.InternalKey, separator []byte,
) error {
// TODO(jackson): Avoid allocating the largest point user key every time we
// set the largest point key. This is what the rowblk writer does too, but
// it's unnecessary.
w.meta.SetLargestPointKey(lastKey.Clone())
w.lastKeyBuf = append(w.lastKeyBuf[:0], lastKey.UserKey...)
w.meta.SetLargestPointKey(base.InternalKey{
UserKey: w.lastKeyBuf,
Trailer: lastKey.Trailer,
})

if invariants.Enabled {
var dec colblk.DataBlockDecoder
Expand Down

0 comments on commit 924a669

Please sign in to comment.