From ae9cd1299cd927dca511344eec1ca16cf91ca758 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Wed, 16 Dec 2020 20:22:58 -0800 Subject: [PATCH] hash/maphash: manually inline setSeed MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Provides a minor performance win. name old time/op new time/op delta Hash8Bytes-8 16.5ns ± 2% 16.5ns ± 4% ~ (p=0.407 n=27+29) Hash320Bytes-8 58.5ns ± 2% 55.0ns ± 2% -6.01% (p=0.000 n=29+28) Hash1K-8 195ns ± 1% 190ns ± 2% -2.23% (p=0.000 n=30+30) Hash8K-8 1.59µs ± 2% 1.57µs ± 2% -0.88% (p=0.002 n=30+30) name old speed new speed delta Hash8Bytes-8 484MB/s ± 2% 485MB/s ± 4% ~ (p=0.417 n=27+29) Hash320Bytes-8 5.47GB/s ± 2% 5.82GB/s ± 2% +6.39% (p=0.000 n=29+28) Hash1K-8 5.26GB/s ± 1% 5.39GB/s ± 2% +2.29% (p=0.000 n=30+30) Hash8K-8 5.16GB/s ± 2% 5.21GB/s ± 2% +0.89% (p=0.002 n=30+30) Updates #42710 Change-Id: Ia0d7264b648f96099202de21c6b69a9c1776f6c8 Reviewed-on: https://go-review.googlesource.com/c/go/+/278759 Trust: Josh Bleecher Snyder Run-TryBot: Josh Bleecher Snyder TryBot-Result: Go Bot Reviewed-by: Ian Lance Taylor --- src/hash/maphash/maphash.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/hash/maphash/maphash.go b/src/hash/maphash/maphash.go index f7ef1b41e8..c45964f89e 100644 --- a/src/hash/maphash/maphash.go +++ b/src/hash/maphash/maphash.go @@ -68,7 +68,9 @@ type Hash struct { // which does call h.initSeed.) func (h *Hash) initSeed() { if h.seed.s == 0 { - h.setSeed(MakeSeed()) + seed := MakeSeed() + h.seed = seed + h.state = seed } } @@ -123,17 +125,12 @@ func (h *Hash) Seed() Seed { // Two Hash objects with different seeds will very likely behave differently. // Any bytes added to h before this call will be discarded. func (h *Hash) SetSeed(seed Seed) { - h.setSeed(seed) - h.n = 0 -} - -// setSeed sets seed without discarding accumulated data. -func (h *Hash) setSeed(seed Seed) { if seed.s == 0 { panic("maphash: use of uninitialized Seed") } h.seed = seed h.state = seed + h.n = 0 } // Reset discards all bytes added to h. -- 2.50.0