From: Michael Anthony Knyszek Date: Mon, 14 Jul 2025 19:33:13 +0000 (+0000) Subject: runtime: use memclrNoHeapPointers to clear inline mark bits X-Git-Tag: go1.25rc3~5^2~20 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=75a19dbcd7;p=gostls13.git runtime: use memclrNoHeapPointers to clear inline mark bits Clearing the inline mark bits with memclrNoHeapPointers is slightly better than having the compiler insert, e.g. duffzero, since it can take advantage of wider SIMD instructions. duffzero is likely going away, but we know things the compiler doesn't, such as the fact that this memory is nicely aligned. In this particular case, memclrNoHeapPointers does a better job. For #73581. Change-Id: I3918096929acfe6efe6f469fb089ebe04b4acff5 Reviewed-on: https://go-review.googlesource.com/c/go/+/687938 Reviewed-by: Michael Pratt Reviewed-by: Cherry Mui LUCI-TryBot-Result: Go LUCI Auto-Submit: Michael Knyszek --- diff --git a/src/runtime/mgcmark_greenteagc.go b/src/runtime/mgcmark_greenteagc.go index 6af711108f..a2f28e95d2 100644 --- a/src/runtime/mgcmark_greenteagc.go +++ b/src/runtime/mgcmark_greenteagc.go @@ -132,7 +132,11 @@ func (imb *spanInlineMarkBits) init(class spanClass, needzero bool) { throw("runtime: span inline mark bits nil?") } if needzero { - *imb = spanInlineMarkBits{} + // Use memclrNoHeapPointers to avoid having the compiler make a worse + // decision. We know that imb is both aligned and a nice power-of-two + // size that works well for wider SIMD instructions. The compiler likely + // has no idea that imb is aligned to 128 bytes. + memclrNoHeapPointers(unsafe.Pointer(imb), unsafe.Sizeof(spanInlineMarkBits{})) } imb.class = class }