Closed
Description
Two little highly-optimised functions suffer from serious performance when compared to Go version 1.9.
name old time/op new time/op delta
PutUint64-12 4.09ns ± 0% 5.79ns ± 0% +41.62% (p=0.000 n=20+19)
Uint64-12 4.24ns ± 0% 6.54ns ± 0% +54.35% (p=0.000 n=20+19)
The assembler output from go build -gcflags=-S
is exactly the same so I don't know where to look for. If anybody can give me some pointers I'd be happy to build a clean test case.
Here follows a snippet from https://github.com/pascaldekloe/flit for context.
// PutUint64 encodes an integer into buf and returns the serial size.
// If the buffer is smaller than 9 bytes, PutUint64 may panic.
func PutUint64(buf []byte, v uint64) (n int) {
if v < 128 {
buf[0] = uint8(v)<<1 | 1
return 1
}
if v >= uint64(1) << 56 {
buf[0] = 0
binary.LittleEndian.PutUint64(buf[1:], v)
return 9
}
lz := bits.LeadingZeros64(v)
// extra bytes = (bits - 1) / 7 = (63 - lz) / 7
e := ((63 - lz) * 2454267027) >> 34
v <<= 1
v |= 1
v <<= uint(e) & 63
binary.LittleEndian.PutUint64(buf, v)
return e + 1
}