]> Cypherpunks repositories - gostls13.git/commitdiff
compress/flate: move big non-pointer arrays to end of compressor
authorIan Lance Taylor <iant@golang.org>
Mon, 29 Sep 2025 04:38:53 +0000 (21:38 -0700)
committerGopher Robot <gobot@golang.org>
Tue, 25 Nov 2025 20:28:05 +0000 (12:28 -0800)
The compressor type is fairly large: 656616 bytes on amd64.
Before this patch, it had fields of slice and interface type
near the end of the struct. As those types always contain pointers,
the ptrBytes value in the type descriptor was quite large.
That forces the garbage collector to do extra work scanning for pointers,
and wastes a bit of executable space recording the gcmask for the type.

This patch moves the arrays to the end of the type,
fixing those minor issues.

Change-Id: I849a75a19cc61137c8797a1ea5a4c97e0f69b4db
Reviewed-on: https://go-review.googlesource.com/c/go/+/707596
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Mark Freeman <markfreeman@google.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
src/compress/flate/deflate.go

index 6697f3a7913cd50f59a7b7fe5edb09f6177ea490..c3862a680ff374d55746eb3bb26f7df98076cadc 100644 (file)
@@ -89,16 +89,6 @@ type compressor struct {
        step      func(*compressor)             // process window
        bestSpeed *deflateFast                  // Encoder for BestSpeed
 
-       // Input hash chains
-       // hashHead[hashValue] contains the largest inputIndex with the specified hash value
-       // If hashHead[hashValue] is within the current window, then
-       // hashPrev[hashHead[hashValue] & windowMask] contains the previous index
-       // with the same hash value.
-       chainHead  int
-       hashHead   [hashSize]uint32
-       hashPrev   [windowSize]uint32
-       hashOffset int
-
        // input window: unprocessed data is window[index:windowEnd]
        index         int
        window        []byte
@@ -117,6 +107,18 @@ type compressor struct {
        maxInsertIndex int
        err            error
 
+       // Input hash chains
+       // hashHead[hashValue] contains the largest inputIndex with the specified hash value
+       // If hashHead[hashValue] is within the current window, then
+       // hashPrev[hashHead[hashValue] & windowMask] contains the previous index
+       // with the same hash value.
+       // These are large and do not contain pointers, so put them
+       // near the end of the struct so the GC has to scan less.
+       chainHead  int
+       hashHead   [hashSize]uint32
+       hashPrev   [windowSize]uint32
+       hashOffset int
+
        // hashMatch must be able to contain hashes for the maximum match length.
        hashMatch [maxMatchLength - 1]uint32
 }