File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,9 @@ package commp
33import (
44 "errors"
55 "fmt"
6+ "hash"
67 "math/bits"
8+ "sync"
79
810 "github.com/filecoin-project/go-commp-utils/zerocomm"
911 commcid "github.com/filecoin-project/go-fil-commcid"
@@ -110,11 +112,14 @@ func PieceAggregateCommP(proofType abi.RegisteredSealProof, pieceInfos []abi.Pie
110112 return commcid .PieceCommitmentV1ToCID (stack [0 ].commP )
111113}
112114
113- var s256 = sha256simd .New ()
115+ var s256pool = sync. Pool { New : func () any { return sha256simd .New () }}
114116
115117func zeroCommForSize (s uint64 ) []byte { return zerocomm .PieceComms [bits .TrailingZeros64 (s )- 7 ][:] }
116118
117119func reduceStack (s []stackFrame ) []stackFrame {
120+
121+ s256 := s256pool .Get ().(hash.Hash )
122+
118123 for len (s ) > 1 && s [len (s )- 2 ].size == s [len (s )- 1 ].size {
119124
120125 s256 .Reset ()
@@ -131,5 +136,7 @@ func reduceStack(s []stackFrame) []stackFrame {
131136 s = s [:len (s )- 1 ]
132137 }
133138
139+ s256pool .Put (s256 )
140+
134141 return s
135142}
You can’t perform that action at this time.
0 commit comments