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:
Seebs 2020-12-09 14:06:14 -06:00
parent 7c415b4217
commit dc67149326
2 changed files with 25 additions and 1 deletions

View file

@ -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]

View file

@ -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