]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: use BestSpeed for DWARF compression
authorAustin Clements <austin@google.com>
Wed, 11 Jul 2018 20:13:04 +0000 (16:13 -0400)
committerAustin Clements <austin@google.com>
Wed, 11 Jul 2018 20:23:02 +0000 (20:23 +0000)
DWARF compression accounts for roughly 30% of the linker's time. This
CL switches from DefaultCompression to BestSpeed, which virtually
eliminates this time. This roughly halves the overhead of handling
DWARF in the linker:

name \ time/op         nodwarf     dwarf        dwarf-speed
BuildCmdGoAll          10.0s ±11%   10.6s ± 5%   10.8s ± 5%
             nodwarf                  +6.41%       +8.03%
               dwarf                                 ~
LinkCmdGo              626ms ± 5%  1096ms ± 2%   860ms ± 2%
             nodwarf                 +75.17%      +37.36%
               dwarf                              -21.59%

Previously, enabling DWARF had a 75% overhead in link time for cmd/go.
This change reduces this overhead to 37% (a 22% reduction).

The effect on binary size is minimal compared to DefaultCompression,
and still substantially better than no compression:

             cmd/go bytes
nodwarf      10106953
dwarf        12159049 nodwarf+20%
dwarf-speed  12408905 nodwarf+23%
dwarf-nozlib 17766473 nodwarf+76%

Updates #26318.

Change-Id: I33bb7caa038a2753c29104501663daf4839e7054
Reviewed-on: https://go-review.googlesource.com/123356
Run-TryBot: Austin Clements <austin@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
src/cmd/link/internal/ld/data.go

index c337c5e7ed6a786119b1ce210ad60200913ae0ae..0ae93f101855504d0a8ebf226e760ce2dc717fba 100644 (file)
@@ -2177,7 +2177,14 @@ func compressSyms(ctxt *Link, syms []*sym.Symbol) []byte {
        binary.BigEndian.PutUint64(sizeBytes[:], uint64(total))
        buf.Write(sizeBytes[:])
 
-       z := zlib.NewWriter(&buf)
+       // Using zlib.BestSpeed achieves very nearly the same
+       // compression levels of zlib.DefaultCompression, but takes
+       // substantially less time. This is important because DWARF
+       // compression can be a significant fraction of link time.
+       z, err := zlib.NewWriterLevel(&buf, zlib.BestSpeed)
+       if err != nil {
+               log.Fatalf("NewWriterLevel failed: %s", err)
+       }
        for _, sym := range syms {
                if _, err := z.Write(sym.P); err != nil {
                        log.Fatalf("compression failed: %s", err)