diff options
author | Daniel Martí <mvdan@mvdan.cc> | 2019-03-08 18:12:07 +0000 |
---|---|---|
committer | Daniel Martí <mvdan@mvdan.cc> | 2019-03-31 10:49:55 +0000 |
commit | e6ad619ad673d7484535afd4185209b0e9aa95c8 (patch) | |
tree | fda2860015bdb417445811a8ffe071837e7cf775 /src/compress | |
parent | 2d41444ad0c1540f064695a9a4678dda6c0d2a51 (diff) | |
download | go-e6ad619ad673d7484535afd4185209b0e9aa95c8.tar.gz go-e6ad619ad673d7484535afd4185209b0e9aa95c8.zip |
cmd/go: further reduce init work
The first biggest offender was crypto/des.init at ~1%. It's
cryptographically broken and the init function is relatively expensive,
which is unfortunate as both crypto/tls and crypto/x509 (and by
extension, cmd/go) import it. Hide the work behind sync.Once.
The second biggest offender was flag.sortFlags at just under 1%, used by
the Visit flagset methods. It allocated two slices, which made a
difference as cmd/go iterates over multiple flagsets during init.
Use a single slice with a direct sort.Interface implementation.
Another big offender is initializing global maps. Reducing this work in
cmd/go/internal/imports and net/textproto gives us close to another
whole 1% in saved work. The former can use map literals, and the latter
can hide the work behind sync.Once.
Finally, compress/flate used newHuffmanBitWriter as part of init, which
allocates many objects and slices. Yet it only used one of the slice
fields. Allocating just that slice saves a surprising ~0.3%, since we
generated a lot of unnecessary garbage.
All in all, these little pieces amount to just over 3% saved CPU time.
name old time/op new time/op delta
ExecGoEnv-8 3.61ms ± 1% 3.50ms ± 0% -3.02% (p=0.000 n=10+10)
Updates #26775.
Updates #29382.
Change-Id: I915416e88a874c63235ba512617c8aef35c0ca8b
Reviewed-on: https://go-review.googlesource.com/c/go/+/166459
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/compress')
-rw-r--r-- | src/compress/flate/huffman_bit_writer.go | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/compress/flate/huffman_bit_writer.go b/src/compress/flate/huffman_bit_writer.go index f42a921e67..3e19061f8b 100644 --- a/src/compress/flate/huffman_bit_writer.go +++ b/src/compress/flate/huffman_bit_writer.go @@ -609,10 +609,10 @@ func (w *huffmanBitWriter) writeTokens(tokens []token, leCodes, oeCodes []hcode) var huffOffset *huffmanEncoder func init() { - w := newHuffmanBitWriter(nil) - w.offsetFreq[0] = 1 + offsetFreq := make([]int32, offsetCodeCount) + offsetFreq[0] = 1 huffOffset = newHuffmanEncoder(offsetCodeCount) - huffOffset.generate(w.offsetFreq, 15) + huffOffset.generate(offsetFreq, 15) } // writeBlockHuff encodes a block of bytes as either |