mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-10 23:11:01 +00:00
read leaf cells through a pointer
This reduces noticably the cost of reading leaf cells, by passing a single pointer down the stack instead of the entire data structure up the stack. It's only a few percent overall, but it's noticeable.
This commit is contained in:
parent
7c415b4217
commit
dc67149326
2 changed files with 25 additions and 1 deletions
23
rbf/rbf.go
23
rbf/rbf.go
|
|
@ -511,6 +511,29 @@ func readLeafCell(page []byte, i int) leafCell {
|
|||
return cell
|
||||
}
|
||||
|
||||
func readLeafCellInto(cell *leafCell, page []byte, i int) {
|
||||
assert(i < readCellN(page)) // cell index exceeds cell count
|
||||
offset := readCellOffset(page, i)
|
||||
|
||||
buf := page[offset:]
|
||||
|
||||
cell.Key = *(*uint64)(unsafe.Pointer(&buf[0]))
|
||||
cell.Type = ContainerType(*(*uint32)(unsafe.Pointer(&buf[8])))
|
||||
cell.ElemN = int(*(*uint16)(unsafe.Pointer(&buf[12])))
|
||||
cell.BitN = int(*(*uint32)(unsafe.Pointer(&buf[14])))
|
||||
|
||||
switch cell.Type {
|
||||
case ContainerTypeArray:
|
||||
cell.Data = buf[leafCellHeaderSize : leafCellHeaderSize+(cell.ElemN*2)]
|
||||
case ContainerTypeRLE:
|
||||
cell.Data = buf[leafCellHeaderSize : leafCellHeaderSize+(cell.ElemN*4)]
|
||||
case ContainerTypeBitmapPtr:
|
||||
cell.Data = buf[leafCellHeaderSize : leafCellHeaderSize+4]
|
||||
default:
|
||||
cell.Data = nil
|
||||
}
|
||||
}
|
||||
|
||||
func readLeafCells(page []byte, buf []leafCell) []leafCell {
|
||||
n := readCellN(page)
|
||||
cells := buf[:n]
|
||||
|
|
|
|||
|
|
@ -1433,10 +1433,11 @@ func (s *containerFilter) Close() {
|
|||
|
||||
func (s *containerFilter) Apply() (err error) {
|
||||
var minKey roaring.FilterKey
|
||||
var cell leafCell
|
||||
for err := s.cursor.Next(); err == nil; err = s.cursor.Next() {
|
||||
elem := &s.cursor.stack.elems[s.cursor.stack.top]
|
||||
leafPage, _, _ := s.cursor.tx.readPage(elem.pgno)
|
||||
cell := readLeafCell(leafPage, elem.index)
|
||||
readLeafCellInto(&cell, leafPage, elem.index)
|
||||
key := roaring.FilterKey(cell.Key)
|
||||
if key < minKey {
|
||||
continue
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue