From d247ed00e498e9717fb7c80d126bee5a8afdb4e8 Mon Sep 17 00:00:00 2001 From: Nick Ripley Date: Fri, 27 Mar 2026 09:35:51 -0400 Subject: runtime: remove redundant fields from memory profile records The memProfCycle struct holds allocation counts and bytes allocated, and frees and bytes freed. But the memory profile records are already aggregated by allocation size, which is stored in the "size" field of the bucket struct. We can derive the bytes allocated/freed using the counts and the size we already store. Thus we can delete the bytes fields from memProfCycle, saving 64 bytes per memRecord. We can do something similar for the profilerecord.MemProfileRecord type. We just need to know the object size and we can derive the allocated and freed bytes accordingly. Change-Id: I103885c2f29471b25283e330674fc16d6a6a6964 Reviewed-on: https://go-review.googlesource.com/c/go/+/760140 LUCI-TryBot-Result: Go LUCI Reviewed-by: Dmitri Shuralyov Reviewed-by: Michael Pratt --- src/runtime/pprof/pprof.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/runtime/pprof/pprof.go') diff --git a/src/runtime/pprof/pprof.go b/src/runtime/pprof/pprof.go index d560eeade1..6708d2dfa3 100644 --- a/src/runtime/pprof/pprof.go +++ b/src/runtime/pprof/pprof.go @@ -674,9 +674,9 @@ func writeHeapInternal(w io.Writer, debug int, defaultSampleType string) error { var total runtime.MemProfileRecord for i := range p { r := &p[i] - total.AllocBytes += r.AllocBytes + total.AllocBytes += r.AllocObjects * r.ObjectSize total.AllocObjects += r.AllocObjects - total.FreeBytes += r.FreeBytes + total.FreeBytes += r.FreeObjects * r.ObjectSize total.FreeObjects += r.FreeObjects } @@ -706,7 +706,7 @@ func writeHeapInternal(w io.Writer, debug int, defaultSampleType string) error { r := &p[i] fmt.Fprintf(w, "%d: %d [%d: %d] @", r.InUseObjects(), r.InUseBytes(), - r.AllocObjects, r.AllocBytes) + r.AllocObjects, r.AllocObjects*r.ObjectSize) for _, pc := range r.Stack { fmt.Fprintf(w, " %#x", pc) } -- cgit v1.3-6-g1900