]> Cypherpunks repositories - gostls13.git/commit
cmd/go: further reduce init work
authorDaniel Martí <mvdan@mvdan.cc>
Fri, 8 Mar 2019 18:12:07 +0000 (18:12 +0000)
committerDaniel Martí <mvdan@mvdan.cc>
Sun, 31 Mar 2019 10:49:55 +0000 (10:49 +0000)
commite6ad619ad673d7484535afd4185209b0e9aa95c8
treefda2860015bdb417445811a8ffe071837e7cf775
parent2d41444ad0c1540f064695a9a4678dda6c0d2a51
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>
src/cmd/go/internal/imports/build.go
src/compress/flate/huffman_bit_writer.go
src/crypto/des/block.go
src/flag/flag.go
src/net/textproto/reader.go
src/net/textproto/reader_test.go