chunks: varint encoding in first full 64bit numbers

This saves about 7 bytes per chunk
This commit is contained in:
Fabian Reinartz 2016-11-30 22:10:10 +01:00
parent 5e76fd3126
commit 8c48dc2ca5
3 changed files with 20 additions and 8 deletions

View File

@ -99,6 +99,10 @@ func (b *bstream) readBit() (bit, error) {
return d != 0, nil
}
func (b *bstream) ReadByte() (byte, error) {
return b.readByte()
}
func (b *bstream) readByte() (byte, error) {
if len(b.stream) == 0 {
return 0, io.EOF

View File

@ -90,7 +90,8 @@ func benchmarkIterator(b *testing.B, newChunk func(int) Chunk) {
)
var exp []pair
for i := 0; i < b.N; i++ {
t += int64(rand.Intn(10000) + 1)
// t += int64(rand.Intn(10000) + 1)
t += int64(1000)
// v = rand.Float64()
v += float64(100)
exp = append(exp, pair{t: t, v: v})
@ -156,7 +157,8 @@ func benchmarkAppender(b *testing.B, newChunk func(int) Chunk) {
)
var exp []pair
for i := 0; i < b.N; i++ {
t += int64(rand.Intn(10000) + 1)
// t += int64(rand.Intn(10000) + 1)
t += int64(1000)
// v = rand.Float64()
v += float64(100)
exp = append(exp, pair{t: t, v: v})

View File

@ -90,14 +90,20 @@ func (a *xorAppender) Append(t int64, v float64) error {
var tDelta uint64
if a.c.num == 0 {
// TODO: store varint time?
a.b.writeBits(uint64(t), 64)
buf := make([]byte, binary.MaxVarintLen64)
for _, b := range buf[:binary.PutVarint(buf, t)] {
a.b.writeByte(b)
}
a.b.writeBits(math.Float64bits(v), 64)
} else if a.c.num == 1 {
tDelta = uint64(t - a.t)
// TODO: use varint or other encoding for first delta?
a.b.writeBits(tDelta, 64)
buf := make([]byte, binary.MaxVarintLen64)
for _, b := range buf[:binary.PutUvarint(buf, tDelta)] {
a.b.writeByte(b)
}
a.writeVDelta(v)
} else {
@ -203,7 +209,7 @@ func (it *xorIterator) Next() bool {
}
if it.numRead == 0 {
t, err := it.br.readBits(64)
t, err := binary.ReadVarint(it.br)
if err != nil {
it.err = err
return false
@ -220,7 +226,7 @@ func (it *xorIterator) Next() bool {
return true
}
if it.numRead == 1 {
tDelta, err := it.br.readBits(64)
tDelta, err := binary.ReadUvarint(it.br)
if err != nil {
it.err = err
return false