[go] internal/abi: set MaxPtrmaskBytes to 16

3 views
Skip to first unread message

Ian Lance Taylor (Gerrit)

unread,
Dec 14, 2025, 2:30:39 PM (2 days ago) Dec 14
to goph...@pubsubhelper.golang.org, Ian Lance Taylor, golang-co...@googlegroups.com

Ian Lance Taylor has uploaded the change for review

Commit message

internal/abi: set MaxPtrmaskBytes to 16

When MaxPtrmaskBytes was introduced in CL 9888, it was given the value 16.
That seemed like a good tradeoff between space in the binary and
code computing the GC bitmask from a GC program.

In CL 10815 MaxPtrmaxBytes was increased to 2048, because that CL
changed channel sending to use typeBitsBulkBarrier, which did not
support GC programs. The value 2048 was chosen to ensure that all
types up to 64K would use a GC bitmask, as channel element types are
limited to 64K.

In CL 616255 GC programs were removed and the GC bitmask,
if not precomputed, was instead generated from the type descriptor.
As part of this change the restriction on typeBitsBulkBarrier was removed.
Thus the requirement of setting MaxPtrmaskBytes to 2048 no longer applies.

This CL restores MaxPtrmaskBytes back to the original value of 16.

For reference, in tailscaled this changes the number of types
requiring the GC bitmask to be computed from 6 to 49.
This saves about 100 bytes in the executable, which I admit isn't much.
On the other hand some of those precomputed bitmasks are never used,
such as the one generated for runtime.spanQueue.
Change-Id: I170baaaa07d9f86e976586de93635c1be820a91e

Change diff

diff --git a/src/internal/abi/type.go b/src/internal/abi/type.go
index e420ce2..8e008d8 100644
--- a/src/internal/abi/type.go
+++ b/src/internal/abi/type.go
@@ -871,31 +871,10 @@

// MaxPtrmaskBytes is the maximum length of a GC ptrmask bitmap,
// which holds 1-bit entries describing where pointers are in a given type.
-// Above this length, the GC information is recorded as a GC program,
-// which can express repetition compactly. In either form, the
-// information is used by the runtime to initialize the heap bitmap,
-// and for large types (like 128 or more words), they are roughly the
-// same speed. GC programs are never much larger and often more
-// compact. (If large arrays are involved, they can be arbitrarily
-// more compact.)
+// Above this length, the runtime computes the GC ptrmask bitmap as needed.
+// The information is used by the runtime to initialize the heap bitmap.
//
-// The cutoff must be large enough that any allocation large enough to
-// use a GC program is large enough that it does not share heap bitmap
-// bytes with any other objects, allowing the GC program execution to
-// assume an aligned start and not use atomic operations. In the current
-// runtime, this means all malloc size classes larger than the cutoff must
-// be multiples of four words. On 32-bit systems that's 16 bytes, and
-// all size classes >= 16 bytes are 16-byte aligned, so no real constraint.
-// On 64-bit systems, that's 32 bytes, and 32-byte alignment is guaranteed
-// for size classes >= 256 bytes. On a 64-bit system, 256 bytes allocated
-// is 32 pointers, the bits for which fit in 4 bytes. So MaxPtrmaskBytes
-// must be >= 4.
-//
-// We used to use 16 because the GC programs do have some constant overhead
-// to get started, and processing 128 pointers seems to be enough to
-// amortize that overhead well.
-//
-// To make sure that the runtime's chansend can call typeBitsBulkBarrier,
-// we raised the limit to 2048, so that even 32-bit systems are guaranteed to
-// use bitmaps for objects up to 64 kB in size.
-const MaxPtrmaskBytes = 2048
+// We use 16 because computing the GC ptrmask bitmap has some overhead
+// the first time the bitmap is required, and processing 128 pointers
+// seems to be enough to amortize that overhead well.
+const MaxPtrmaskBytes = 16

Change information

Files:
  • M src/internal/abi/type.go
Change size: S
Delta: 1 file changed, 6 insertions(+), 27 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I170baaaa07d9f86e976586de93635c1be820a91e
Gerrit-Change-Number: 730000
Gerrit-PatchSet: 1
Gerrit-Owner: Ian Lance Taylor <ia...@golang.org>
unsatisfied_requirement
satisfied_requirement
open
diffy

Ian Lance Taylor (Gerrit)

unread,
Dec 14, 2025, 2:30:52 PM (2 days ago) Dec 14
to Ian Lance Taylor, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Ian Lance Taylor voted Commit-Queue+1

Commit-Queue+1
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I170baaaa07d9f86e976586de93635c1be820a91e
Gerrit-Change-Number: 730000
Gerrit-PatchSet: 1
Gerrit-Owner: Ian Lance Taylor <ia...@golang.org>
Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
Gerrit-Comment-Date: Sun, 14 Dec 2025 19:30:49 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy

Michael Knyszek (Gerrit)

unread,
Dec 15, 2025, 11:16:11 AM (yesterday) Dec 15
to Ian Lance Taylor, goph...@pubsubhelper.golang.org, Go LUCI, Cherry Mui, Gopher Robot, golang-co...@googlegroups.com
Attention needed from Cherry Mui and Ian Lance Taylor

Michael Knyszek added 1 comment

File src/internal/abi/type.go
Line 878, Patchset 1 (Latest):// the first time the bitmap is required, and processing 128 pointers

// seems to be enough to amortize that overhead well.
Michael Knyszek . unresolved

I don't know that this is true anymore.

looking at the code path, after first use, we're just adding an extra indirection and a couple predictable branches (https://cs.opensource.google/go/go/+/master:src/runtime/type.go;l=116?q=getGCMaskOn&ss=go%2Fgo), it may be that this actually scales down further (but I doubt we gain much by doing so).

either way, my point is I think we should just drop this part of the comment and we should state that 16 is arbitrary. or we could just measure it again. (for instance, we could simulate the inner loop of runtime.scanObject, specifically the iteration part, in a benchmark, and find the point where the extra cost disappears.)

Open in Gerrit

Related details

Attention is currently required from:
  • Cherry Mui
  • Ian Lance Taylor
Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I170baaaa07d9f86e976586de93635c1be820a91e
    Gerrit-Change-Number: 730000
    Gerrit-PatchSet: 1
    Gerrit-Owner: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Reviewer: Cherry Mui <cher...@google.com>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Attention: Cherry Mui <cher...@google.com>
    Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Comment-Date: Mon, 15 Dec 2025 16:16:08 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy

    Ian Lance Taylor (Gerrit)

    unread,
    Dec 15, 2025, 7:12:41 PM (19 hours ago) Dec 15
    to Ian Lance Taylor, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
    Attention needed from Cherry Mui and Ian Lance Taylor

    Ian Lance Taylor uploaded new patchset

    Ian Lance Taylor uploaded patch set #2 to this change.
    Following approvals got outdated and were removed:
    • TryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Cherry Mui
    • Ian Lance Taylor
    Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: newpatchset
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I170baaaa07d9f86e976586de93635c1be820a91e
      Gerrit-Change-Number: 730000
      Gerrit-PatchSet: 2
      unsatisfied_requirement
      open
      diffy

      Ian Lance Taylor (Gerrit)

      unread,
      Dec 15, 2025, 7:14:46 PM (19 hours ago) Dec 15
      to Ian Lance Taylor, goph...@pubsubhelper.golang.org, Go LUCI, Michael Knyszek, Cherry Mui, Gopher Robot, golang-co...@googlegroups.com
      Attention needed from Cherry Mui and Michael Knyszek

      Ian Lance Taylor voted and added 1 comment

      Votes added by Ian Lance Taylor

      Commit-Queue+1

      1 comment

      File src/internal/abi/type.go
      Line 878, Patchset 1:// the first time the bitmap is required, and processing 128 pointers

      // seems to be enough to amortize that overhead well.
      Michael Knyszek . resolved

      I don't know that this is true anymore.

      looking at the code path, after first use, we're just adding an extra indirection and a couple predictable branches (https://cs.opensource.google/go/go/+/master:src/runtime/type.go;l=116?q=getGCMaskOn&ss=go%2Fgo), it may be that this actually scales down further (but I doubt we gain much by doing so).

      either way, my point is I think we should just drop this part of the comment and we should state that 16 is arbitrary. or we could just measure it again. (for instance, we could simulate the inner loop of runtime.scanObject, specifically the iteration part, in a benchmark, and find the point where the extra cost disappears.)

      Ian Lance Taylor

      Good point. And now I feel bad because I haven't done any benchmarking. But not enough to actually try to do a real benchmark. It seems likely that any effect is going to be marginal either way.

      Anyhow I updated the comment to be more honest.

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Cherry Mui
      • Michael Knyszek
      Submit Requirements:
        • requirement is not satisfiedCode-Review
        • requirement satisfiedNo-Unresolved-Comments
        • requirement is not satisfiedReview-Enforcement
        • requirement is not satisfiedTryBots-Pass
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: I170baaaa07d9f86e976586de93635c1be820a91e
        Gerrit-Change-Number: 730000
        Gerrit-PatchSet: 2
        Gerrit-Owner: Ian Lance Taylor <ia...@golang.org>
        Gerrit-Reviewer: Cherry Mui <cher...@google.com>
        Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
        Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
        Gerrit-CC: Gopher Robot <go...@golang.org>
        Gerrit-Attention: Cherry Mui <cher...@google.com>
        Gerrit-Attention: Michael Knyszek <mkny...@google.com>
        Gerrit-Comment-Date: Tue, 16 Dec 2025 00:14:40 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: Yes
        Comment-In-Reply-To: Michael Knyszek <mkny...@google.com>
        unsatisfied_requirement
        satisfied_requirement
        open
        diffy

        Michael Knyszek (Gerrit)

        unread,
        Dec 15, 2025, 10:35:03 PM (16 hours ago) Dec 15
        to Ian Lance Taylor, goph...@pubsubhelper.golang.org, Go LUCI, Cherry Mui, Gopher Robot, golang-co...@googlegroups.com
        Attention needed from Cherry Mui and Ian Lance Taylor

        Michael Knyszek added 1 comment

        File src/internal/abi/type.go
        Line 878, Patchset 1:// the first time the bitmap is required, and processing 128 pointers
        // seems to be enough to amortize that overhead well.
        Michael Knyszek . resolved

        I don't know that this is true anymore.

        looking at the code path, after first use, we're just adding an extra indirection and a couple predictable branches (https://cs.opensource.google/go/go/+/master:src/runtime/type.go;l=116?q=getGCMaskOn&ss=go%2Fgo), it may be that this actually scales down further (but I doubt we gain much by doing so).

        either way, my point is I think we should just drop this part of the comment and we should state that 16 is arbitrary. or we could just measure it again. (for instance, we could simulate the inner loop of runtime.scanObject, specifically the iteration part, in a benchmark, and find the point where the extra cost disappears.)

        Ian Lance Taylor

        Good point. And now I feel bad because I haven't done any benchmarking. But not enough to actually try to do a real benchmark. It seems likely that any effect is going to be marginal either way.

        Anyhow I updated the comment to be more honest.

        Michael Knyszek

        It seems likely that any effect is going to be marginal either way.

        agreed! benchmarking it to find the true cutoff is almost certainly overkill.

        thanks for updating the comment.

        Open in Gerrit

        Related details

        Attention is currently required from:
        • Cherry Mui
        • Ian Lance Taylor
        Submit Requirements:
          • requirement is not satisfiedCode-Review
          • requirement satisfiedNo-Unresolved-Comments
          • requirement is not satisfiedReview-Enforcement
          • requirement satisfiedTryBots-Pass
          Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
          Gerrit-MessageType: comment
          Gerrit-Project: go
          Gerrit-Branch: master
          Gerrit-Change-Id: I170baaaa07d9f86e976586de93635c1be820a91e
          Gerrit-Change-Number: 730000
          Gerrit-PatchSet: 2
          Gerrit-Owner: Ian Lance Taylor <ia...@golang.org>
          Gerrit-Reviewer: Cherry Mui <cher...@google.com>
          Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
          Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
          Gerrit-CC: Gopher Robot <go...@golang.org>
          Gerrit-Attention: Cherry Mui <cher...@google.com>
          Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
          Gerrit-Comment-Date: Tue, 16 Dec 2025 03:35:00 +0000
          Gerrit-HasComments: Yes
          Gerrit-Has-Labels: No
          Comment-In-Reply-To: Ian Lance Taylor <ia...@golang.org>
          Comment-In-Reply-To: Michael Knyszek <mkny...@google.com>
          unsatisfied_requirement
          satisfied_requirement
          open
          diffy

          Michael Knyszek (Gerrit)

          unread,
          Dec 15, 2025, 10:35:53 PM (16 hours ago) Dec 15
          to Ian Lance Taylor, goph...@pubsubhelper.golang.org, Go LUCI, Cherry Mui, Gopher Robot, golang-co...@googlegroups.com
          Attention needed from Cherry Mui and Ian Lance Taylor

          Michael Knyszek voted Code-Review+2

          Code-Review+2
          Open in Gerrit

          Related details

          Attention is currently required from:
          • Cherry Mui
          • Ian Lance Taylor
          Submit Requirements:
          • requirement satisfiedCode-Review
          • requirement satisfiedNo-Unresolved-Comments
          • requirement is not satisfiedReview-Enforcement
          • requirement satisfiedTryBots-Pass
          Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
          Gerrit-MessageType: comment
          Gerrit-Project: go
          Gerrit-Branch: master
          Gerrit-Change-Id: I170baaaa07d9f86e976586de93635c1be820a91e
          Gerrit-Change-Number: 730000
          Gerrit-PatchSet: 2
          Gerrit-Owner: Ian Lance Taylor <ia...@golang.org>
          Gerrit-Reviewer: Cherry Mui <cher...@google.com>
          Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
          Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
          Gerrit-CC: Gopher Robot <go...@golang.org>
          Gerrit-Attention: Cherry Mui <cher...@google.com>
          Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
          Gerrit-Comment-Date: Tue, 16 Dec 2025 03:35:49 +0000
          Gerrit-HasComments: No
          Gerrit-Has-Labels: Yes
          satisfied_requirement
          unsatisfied_requirement
          open
          diffy

          Ian Lance Taylor (Gerrit)

          unread,
          Dec 15, 2025, 11:07:39 PM (15 hours ago) Dec 15
          to Ian Lance Taylor, goph...@pubsubhelper.golang.org, Go LUCI, Cherry Mui, Gopher Robot, golang-co...@googlegroups.com
          Attention needed from Cherry Mui

          Ian Lance Taylor added 1 comment

          File src/internal/abi/type.go
          Line 878, Patchset 1:// the first time the bitmap is required, and processing 128 pointers
          // seems to be enough to amortize that overhead well.
          Michael Knyszek . resolved

          I don't know that this is true anymore.

          looking at the code path, after first use, we're just adding an extra indirection and a couple predictable branches (https://cs.opensource.google/go/go/+/master:src/runtime/type.go;l=116?q=getGCMaskOn&ss=go%2Fgo), it may be that this actually scales down further (but I doubt we gain much by doing so).

          either way, my point is I think we should just drop this part of the comment and we should state that 16 is arbitrary. or we could just measure it again. (for instance, we could simulate the inner loop of runtime.scanObject, specifically the iteration part, in a benchmark, and find the point where the extra cost disappears.)

          Ian Lance Taylor

          Good point. And now I feel bad because I haven't done any benchmarking. But not enough to actually try to do a real benchmark. It seems likely that any effect is going to be marginal either way.

          Anyhow I updated the comment to be more honest.

          Michael Knyszek

          It seems likely that any effect is going to be marginal either way.

          agreed! benchmarking it to find the true cutoff is almost certainly overkill.

          thanks for updating the comment.

          Ian Lance Taylor

          Thanks.

          Open in Gerrit

          Related details

          Attention is currently required from:
          • Cherry Mui
          Submit Requirements:
            • requirement satisfiedCode-Review
            • requirement satisfiedNo-Unresolved-Comments
            • requirement is not satisfiedNo-Wait-Release
            • requirement is not satisfiedReview-Enforcement
            • requirement satisfiedTryBots-Pass
            Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
            Gerrit-MessageType: comment
            Gerrit-Project: go
            Gerrit-Branch: master
            Gerrit-Change-Id: I170baaaa07d9f86e976586de93635c1be820a91e
            Gerrit-Change-Number: 730000
            Gerrit-PatchSet: 2
            Gerrit-Owner: Ian Lance Taylor <ia...@golang.org>
            Gerrit-Reviewer: Cherry Mui <cher...@google.com>
            Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
            Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
            Gerrit-CC: Gopher Robot <go...@golang.org>
            Gerrit-Attention: Cherry Mui <cher...@google.com>
            Gerrit-Comment-Date: Tue, 16 Dec 2025 04:07:33 +0000
            satisfied_requirement
            unsatisfied_requirement
            open
            diffy
            Reply all
            Reply to author
            Forward
            0 new messages