go/src/compress
Daniel Martí e6ad619ad6 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>
2019-03-31 10:49:55 +00:00
..
bzip2 compress: reduce copies of new text for compression testing 2018-09-24 18:26:02 +00:00
flate cmd/go: further reduce init work 2019-03-31 10:49:55 +00:00
gzip compress/gzip: clarify that Multistream gzip requires a ByteReader 2019-02-26 23:02:40 +00:00
lzw all: update comment URLs from HTTP to HTTPS, where possible 2018-06-01 21:52:00 +00:00
testdata Revert "compress: move benchmark text from src/testdata to src/compress/testdata" 2018-10-01 16:16:21 +00:00
zlib all: fix a bunch of misspellings 2018-10-06 15:40:03 +00:00