From f07ce297f6c644f5632e750b9e98fb0d82d571df Mon Sep 17 00:00:00 2001 From: vyzo Date: Wed, 26 Jan 2022 21:55:24 +0200 Subject: [PATCH] optimize slice allocations in walk --- blockstore/splitstore/splitstore_compact.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/blockstore/splitstore/splitstore_compact.go b/blockstore/splitstore/splitstore_compact.go index 9ab718929..20f99af35 100644 --- a/blockstore/splitstore/splitstore_compact.go +++ b/blockstore/splitstore/splitstore_compact.go @@ -624,7 +624,9 @@ func (s *SplitStore) walkChain(ts *types.TipSet, inclState, inclMsgs abi.ChainEp visitor ObjectVisitor, f func(cid.Cid) error) error { var walked ObjectVisitor var mx sync.Mutex - toWalk := ts.Cids() + // we copy the tipset first into a new slice, which allows us to reuse it in every epoch. + toWalk := make([]cid.Cid, len(ts.Cids())) + copy(toWalk, ts.Cids()) walkCnt := new(int64) scanCnt := new(int64) @@ -717,7 +719,7 @@ func (s *SplitStore) walkChain(ts *types.TipSet, inclState, inclMsgs abi.ChainEp workch <- c } close(workch) - toWalk = nil + toWalk = toWalk[:0] g := new(errgroup.Group) for i := 0; i < workers; i++ {