From 72047317498700d349afa15b370d3ba8e88fa417 Mon Sep 17 00:00:00 2001 From: Lisandro Pin Date: Tue, 3 Jun 2025 02:09:01 +0200 Subject: [PATCH] Minor fix for the `CompactMap()` performance test. (#6836) Per-entry memory usage is based on `TotalAllocs`, which is incorrect - that value is a cummulative of heap usage, which doesn't decrease when objects are freeed. `Allocs` is instead an accurate represeentation of actual memory usage at the time metrics are reported. --- weed/storage/needle_map/compact_map_perf_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/weed/storage/needle_map/compact_map_perf_test.go b/weed/storage/needle_map/compact_map_perf_test.go index 2bb2694fd..e1fb1b035 100644 --- a/weed/storage/needle_map/compact_map_perf_test.go +++ b/weed/storage/needle_map/compact_map_perf_test.go @@ -16,7 +16,7 @@ import ( To see the memory usage: go test -run TestMemoryUsage -The TotalAlloc section shows the memory increase for each iteration. +The Alloc section shows the in-use memory increase for each iteration. go test -run TestMemoryUsage -memprofile=mem.out go tool pprof --alloc_space needle.test mem.out @@ -81,7 +81,7 @@ func PrintMemUsage(totalRowCount uint64) { var m runtime.MemStats runtime.ReadMemStats(&m) // For info on each, see: https://golang.org/pkg/runtime/#MemStats - fmt.Printf("Each %.2f Bytes", float64(m.TotalAlloc)/float64(totalRowCount)) + fmt.Printf("Each %.02f Bytes", float64(m.Alloc)/float64(totalRowCount)) fmt.Printf("\tAlloc = %v MiB", bToMb(m.Alloc)) fmt.Printf("\tTotalAlloc = %v MiB", bToMb(m.TotalAlloc)) fmt.Printf("\tSys = %v MiB", bToMb(m.Sys))