From 76e7875c1b1fe915ff7f2228c4a65ee384e8f7f3 Mon Sep 17 00:00:00 2001 From: Matus Kysel Date: Wed, 4 Jun 2025 12:50:33 +0200 Subject: [PATCH] hash: remove caching that was decreasing perf --- crypto/crypto.go | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/crypto/crypto.go b/crypto/crypto.go index 36ce7c753c..ecc4a1b196 100644 --- a/crypto/crypto.go +++ b/crypto/crypto.go @@ -30,8 +30,6 @@ import ( "os" "sync" - "github.com/VictoriaMetrics/fastcache" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/rlp" @@ -50,8 +48,6 @@ const DigestLength = 32 var ( secp256k1N = S256().Params().N secp256k1halfN = new(big.Int).Div(secp256k1N, big.NewInt(2)) - - keccakState256Cache = fastcache.New(100 * 1024 * 1024) ) var errInvalidPubkey = errors.New("invalid secp256k1 public key") @@ -85,23 +81,14 @@ func NewKeccakState() KeccakState { // HashData hashes the provided data using the KeccakState and returns a 32 byte hash func HashData(kh KeccakState, data []byte) (h common.Hash) { - if hash, ok := keccakState256Cache.HasGet(nil, data); ok { - return common.BytesToHash(hash) - } kh.Reset() kh.Write(data) kh.Read(h[:]) - keccakState256Cache.Set(data, h.Bytes()) return h } // Keccak256 calculates and returns the Keccak256 hash of the input data. func Keccak256(data ...[]byte) []byte { - if len(data) == 1 { - if hash, ok := keccakState256Cache.HasGet(nil, data[0]); ok { - return hash - } - } b := make([]byte, 32) d := keccakState256Pool.Get().(KeccakState) defer keccakState256Pool.Put(d) @@ -110,20 +97,12 @@ func Keccak256(data ...[]byte) []byte { d.Write(b) } d.Read(b) - if len(data) == 1 { - keccakState256Cache.Set(data[0], b) - } return b } // Keccak256Hash calculates and returns the Keccak256 hash of the input data, // converting it to an internal Hash data structure. func Keccak256Hash(data ...[]byte) (h common.Hash) { - if len(data) == 1 { - if hash, ok := keccakState256Cache.HasGet(nil, data[0]); ok { - return common.BytesToHash(hash) - } - } d := keccakState256Pool.Get().(KeccakState) defer keccakState256Pool.Put(d) d.Reset() @@ -131,9 +110,6 @@ func Keccak256Hash(data ...[]byte) (h common.Hash) { d.Write(b) } d.Read(h[:]) - if len(data) == 1 { - keccakState256Cache.Set(data[0], h.Bytes()) - } return h }