From 0b13632ae2dd41823ad6156bf2cb4fcf6cfe9ce8 Mon Sep 17 00:00:00 2001 From: jsvisa Date: Thu, 4 Sep 2025 19:24:18 +0800 Subject: [PATCH] fix: special case for the prefix only key --- core/state/state_sizer.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/core/state/state_sizer.go b/core/state/state_sizer.go index 0f864cfacd..a66e4d3a25 100644 --- a/core/state/state_sizer.go +++ b/core/state/state_sizer.go @@ -21,6 +21,7 @@ import ( "errors" "fmt" "maps" + "runtime" "slices" "sync" "time" @@ -565,7 +566,7 @@ func (t *SizeTracker) iterateTable(closed chan struct{}, prefix []byte, name str func (t *SizeTracker) iterateTableParallel(closed chan struct{}, prefix []byte, name string) (int64, int64, error) { var ( start = time.Now() - workers = 16 + workers = runtime.NumCPU() totalCount int64 totalBytes int64 group errgroup.Group @@ -575,6 +576,14 @@ func (t *SizeTracker) iterateTableParallel(closed chan struct{}, prefix []byte, log.Info("Starting parallel state iteration", "category", name, "workers", workers) + if len(prefix) > 0 { + if blob, err := t.db.Get(prefix); err == nil && len(blob) > 0 { + // If there's a direct hit on the prefix, include it in the stats + totalCount = 1 + totalBytes = int64(len(prefix) + len(blob)) + } + } + for i := 0; i < 256; i++ { h := byte(i) group.Go(func() error {