Check-in [90877fa64f]
Overview
SHA1:90877fa64fa2a38e082a8eb74161a9a1f43ffd8d
Date: 2015-01-11 08:44:26
User: spaskalev
Comment:Switched encoding/fibonacci.Encoder back to using a 2-bytes array as a preallocated write buffer. It seems that it otherwise escapes everytime and calls a causes a lot of allocations and subsequent gc work.
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | folders | manifest
Tags And Properties
Context
2015-01-14
20:46
[3ea011cf07] Use for range in mtf's encoder for the position table. (user: spaskalev, tags: trunk)
2015-01-11
08:44
[90877fa64f] Switched encoding/fibonacci.Encoder back to using a 2-bytes array as a preallocated write buffer. It seems that it otherwise escapes everytime and calls a causes a lot of allocations and subsequent gc work. (user: spaskalev, tags: trunk)
2015-01-10
21:28
[5c9c0a2164] encoding/mtf optimizations (user: spaskalev, tags: trunk)
Changes

Modified src/0dev.org/encoding/fibonacci/fib.go from [32c0b16287] to [ad0ff53aaf].

    98     98   	var enc encoder
    99     99   	enc.target = target
   100    100   	return &enc
   101    101   }
   102    102   
   103    103   type encoder struct {
   104    104   	target    io.Writer
          105  +	buffer    [2]byte
   105    106   	remaining byte
   106    107   	length    byte
   107    108   }
   108    109   
   109    110   // Implements io.Writer
   110    111   func (e *encoder) Write(input []byte) (int, error) {
   111    112   	var (
................................................................................
   141    142   
   142    143   			continue
   143    144   		}
   144    145   
   145    146   		// Clearing e.length is not necessary as it will be overwritten later
   146    147   
   147    148   		// Stage the complete byte for writing
   148         -		buffer := make([]byte, 1, 2)
          149  +		buffer := e.buffer[:1]
   149    150   		buffer[0] = byte(e.remaining)
   150    151   
   151    152   		// Stage every full byte from the encoded value for writing
   152    153   		//
   153    154   		// The bitlength of the largest encoded byte value, 255, is 13.
   154    155   		// Even with 7 bits already in the buffer this leaves [7+1], [8]
   155    156   		// and 4 bits remaining => a single if is enough instead of a for.