From fa4337c3703e926cfd69c567a75030c9d2bc5e9d Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Sun, 16 Aug 2015 18:59:09 -0400 Subject: [PATCH] stream: reduce allocs in Reset() improvement: ``` benchmark old ns/op new ns/op delta BenchmarkHash8Bytes 21137 12201 -42.28% BenchmarkHash1K 27235 14842 -45.50% BenchmarkHash8K 38630 29034 -24.84% benchmark old MB/s new MB/s speedup BenchmarkHash8Bytes 0.38 0.66 1.74x BenchmarkHash1K 37.60 68.99 1.83x BenchmarkHash8K 212.06 282.15 1.33x benchmark old allocs new allocs delta BenchmarkHash8Bytes 10 9 -10.00% BenchmarkHash1K 10 9 -10.00% BenchmarkHash8K 9 8 -11.11% benchmark old bytes new bytes delta BenchmarkHash8Bytes 16712 8520 -49.02% BenchmarkHash1K 17728 9536 -46.21% BenchmarkHash8K 16704 8512 -49.04% ``` --- stream.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stream.go b/stream.go index 068bb0c..68d18d1 100644 --- a/stream.go +++ b/stream.go @@ -49,8 +49,9 @@ type merkleHash struct { } func (mh *merkleHash) Reset() { - mh1 := newMerkleHash(mh.hm, mh.blockSize) - *mh = *mh1 + mh.tree = &Tree{Nodes: []*Node{}, BlockLength: mh.blockSize} + mh.lastBlockLen = 0 + mh.partialLastNode = false } func (mh merkleHash) Nodes() []*Node {