Skip to content

Commit 12ed0dd

Browse files
committed
cmd/link: use BestSpeed for DWARF compression
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 <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]>
1 parent 9300d22 commit 12ed0dd

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/cmd/link/internal/ld/data.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2177,7 +2177,14 @@ func compressSyms(ctxt *Link, syms []*sym.Symbol) []byte {
21772177
binary.BigEndian.PutUint64(sizeBytes[:], uint64(total))
21782178
buf.Write(sizeBytes[:])
21792179

2180-
z := zlib.NewWriter(&buf)
2180+
// Using zlib.BestSpeed achieves very nearly the same
2181+
// compression levels of zlib.DefaultCompression, but takes
2182+
// substantially less time. This is important because DWARF
2183+
// compression can be a significant fraction of link time.
2184+
z, err := zlib.NewWriterLevel(&buf, zlib.BestSpeed)
2185+
if err != nil {
2186+
log.Fatalf("NewWriterLevel failed: %s", err)
2187+
}
21812188
for _, sym := range syms {
21822189
if _, err := z.Write(sym.P); err != nil {
21832190
log.Fatalf("compression failed: %s", err)

0 commit comments

Comments
 (0)