Commit 1d31475a authored by Kirill Smelkov's avatar Kirill Smelkov

X fs1: Speedump index loading a bit

Code generated for

	copy(posb[2:], posBuf[i*6:])
	pos := int64(binary.BigEndian.Uint64(posb[:]))

was awful.

name         old time/op    new time/op    delta
IndexLoad-4    3.06ms ± 0%    2.49ms ± 1%  -18.71%  (p=0.000 n=9+10)
parent a452276d
...@@ -65,6 +65,7 @@ func fsIndexNew() *fsIndex { ...@@ -65,6 +65,7 @@ func fsIndexNew() *fsIndex {
const ( const (
oidPrefixMask zodb.Oid = (1<<64-1) ^ (1<<16 - 1) // 0xffffffffffff0000 oidPrefixMask zodb.Oid = (1<<64-1) ^ (1<<16 - 1) // 0xffffffffffff0000
posInvalidMask uint64 = (1<<64-1) ^ (1<<48 - 1) // 0xffff000000000000 posInvalidMask uint64 = (1<<64-1) ^ (1<<48 - 1) // 0xffff000000000000
posValidMask uint64 = 1<<48 - 1 // 0x0000ffffffffffff
) )
// IndexSaveError is the error type returned by index save routines // IndexSaveError is the error type returned by index save routines
...@@ -230,7 +231,6 @@ func LoadIndex(r io.Reader) (topPos int64, fsi *fsIndex, err error) { ...@@ -230,7 +231,6 @@ func LoadIndex(r io.Reader) (topPos int64, fsi *fsIndex, err error) {
fsi = fsIndexNew() fsi = fsIndexNew()
var oidb [8]byte var oidb [8]byte
var posb [8]byte
loop: loop:
for { for {
...@@ -295,13 +295,12 @@ func LoadIndex(r io.Reader) (topPos int64, fsi *fsIndex, err error) { ...@@ -295,13 +295,12 @@ func LoadIndex(r io.Reader) (topPos int64, fsi *fsIndex, err error) {
n := len(kvBuf) / 8 n := len(kvBuf) / 8
oidBuf := kvBuf[:n*2] oidBuf := kvBuf[:n*2]
posBuf := kvBuf[n*2:] posBuf := kvBuf[n*2-2:] // NOTE starting 2 bytes behind
for i:=0; i<n; i++ { for i:=0; i<n; i++ {
oid := zodb.Oid(binary.BigEndian.Uint16(oidBuf[i*2:])) oid := zodb.Oid(binary.BigEndian.Uint16(oidBuf[i*2:]))
oid |= oidPrefix oid |= oidPrefix
copy(posb[2:], posBuf[i*6:]) pos := int64(binary.BigEndian.Uint64(posBuf[i*6:]) & posValidMask)
pos := int64(binary.BigEndian.Uint64(posb[:]))
fsi.Set(oid, pos) fsi.Set(oid, pos)
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment