Skip to content

Commit

Permalink
colblk: use pointer receiver for RawBytes, PrefixBytes
Browse files Browse the repository at this point in the history
```
goos: darwin
goarch: arm64
pkg: github.com/cockroachdb/pebble/sstable/colblk
                                     │ prefixbytes-old.txt │         prefixbytes-new.txt         │
                                     │       sec/op        │   sec/op     vs base                │
PrefixBytes/alphaLen=2/iteration-10            22.61n ± 0%   18.99n ± 1%  -16.03% (p=0.000 n=20)
PrefixBytes/alphaLen=5/iteration-10            23.18n ± 2%   19.68n ± 4%  -15.12% (p=0.000 n=20)
PrefixBytes/alphaLen=26/iteration-10           23.62n ± 0%   19.68n ± 0%  -16.68% (p=0.000 n=20)
geomean                                        23.13n        19.44n       -15.95%
```
  • Loading branch information
jbowens committed Aug 6, 2024
1 parent daeeafe commit aacee0a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
16 changes: 8 additions & 8 deletions sstable/colblk/prefix_bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func (b PrefixBytes) At(i int) []byte {

// AppendAt appends the i'th []byte slice in the PrefixBytes onto the provided
// bytes slice.
func (b PrefixBytes) AppendAt(dst []byte, i int) []byte {
func (b *PrefixBytes) AppendAt(dst []byte, i int) []byte {
dst = append(dst, b.SharedPrefix()...)
dst = append(dst, b.RowBundlePrefix(i)...)
return append(dst, b.RowSuffix(i)...)
Expand All @@ -249,23 +249,23 @@ func (b PrefixBytes) AppendAt(dst []byte, i int) []byte {
// SharedPrefix return a []byte of the shared prefix that was extracted from
// all of the values in the Bytes vector. The returned slice should not be
// mutated.
func (b PrefixBytes) SharedPrefix() []byte {
func (b *PrefixBytes) SharedPrefix() []byte {
// The very first slice is the prefix for the entire column.
return b.rawBytes.slice(0, b.rawBytes.offsets.At(0))
}

// RowBundlePrefix takes a row index and returns a []byte of the prefix shared
// among all the keys in the row's bundle, but without the block-level shared
// prefix for the column. The returned slice should not be mutated.
func (b PrefixBytes) RowBundlePrefix(row int) []byte {
func (b *PrefixBytes) RowBundlePrefix(row int) []byte {
i := b.bundleOffsetIndexForRow(row)
return b.rawBytes.slice(b.rawBytes.offsets.At(i), b.rawBytes.offsets.At(i+1))
}

// BundlePrefix returns the prefix of the i-th bundle in the column. The
// provided i must be in the range [0, BundleCount()). The returned slice should
// not be mutated.
func (b PrefixBytes) BundlePrefix(i int) []byte {
func (b *PrefixBytes) BundlePrefix(i int) []byte {
j := b.offsetIndexByBundleIndex(i)
return b.rawBytes.slice(b.rawBytes.offsets.At(j), b.rawBytes.offsets.At(j+1))
}
Expand All @@ -275,7 +275,7 @@ func (b PrefixBytes) BundlePrefix(i int) []byte {
// RowSuffix().
//
// The returned slice should not be mutated.
func (b PrefixBytes) RowSuffix(row int) []byte {
func (b *PrefixBytes) RowSuffix(row int) []byte {
i := b.rowSuffixIndex(row)
// Retrieve the low and high offsets indicating the start and end of the
// row's suffix slice.
Expand Down Expand Up @@ -306,20 +306,20 @@ func (b PrefixBytes) RowSuffix(row int) []byte {
}

// Rows returns the count of rows whose keys are encoded within the PrefixBytes.
func (b PrefixBytes) Rows() int {
func (b *PrefixBytes) Rows() int {
return b.rows
}

// BundleCount returns the count of bundles within the PrefixBytes.
func (b PrefixBytes) BundleCount() int {
func (b *PrefixBytes) BundleCount() int {
return b.bundleCount(b.rows)
}

// Search searchs for the first key in the PrefixBytes that is greater than or
// equal to k, returning the index of the key and whether an equal key was
// found. If multiple keys are equal, the index of the first such key is
// returned. If all keys are < k, Search returns Rows() for the row index.
func (b PrefixBytes) Search(k []byte) (rowIndex int, isEqual bool) {
func (b *PrefixBytes) Search(k []byte) (rowIndex int, isEqual bool) {
// First compare to the block-level shared prefix.
n := min(len(k), b.sharedPrefixLen)
c := bytes.Compare(k[:n], unsafe.Slice((*byte)(b.rawBytes.data), b.sharedPrefixLen))
Expand Down
6 changes: 3 additions & 3 deletions sstable/colblk/raw_bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ func rawBytesToBinFormatter(f *binfmt.Formatter, count int, sliceFormatter func(
}
}

func (b RawBytes) ptr(offset uint32) unsafe.Pointer {
func (b *RawBytes) ptr(offset uint32) unsafe.Pointer {
return unsafe.Pointer(uintptr(b.data) + uintptr(offset))
}

func (b RawBytes) slice(start, end uint32) []byte {
func (b *RawBytes) slice(start, end uint32) []byte {
return unsafe.Slice((*byte)(b.ptr(start)), end-start)
}

Expand All @@ -109,7 +109,7 @@ func (b RawBytes) At(i int) []byte {
}

// Slices returns the number of []byte slices encoded within the RawBytes.
func (b RawBytes) Slices() int {
func (b *RawBytes) Slices() int {
return b.slices
}

Expand Down

0 comments on commit aacee0a

Please sign in to comment.