core/vm: add precompile cache

This commit is contained in:
MariusVanDerWijden 2025-06-11 15:32:01 +02:00
parent ec880b1737
commit 759f0100e0

View file

@ -1,17 +1,24 @@
package vm
import (
"sync"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/lru"
)
var caches map[common.Address]*lru.Cache[string, []byte]
var (
caches map[common.Address]*lru.Cache[string, []byte]
mu sync.RWMutex
)
func init() {
caches = make(map[common.Address]*lru.Cache[string, []byte])
}
func addCache(precompile common.Address, input, output []byte) {
mu.Lock()
defer mu.Unlock()
cache, ok := caches[precompile]
if !ok {
cache = lru.NewCache[string, []byte](128)
@ -21,6 +28,8 @@ func addCache(precompile common.Address, input, output []byte) {
}
func getCache(precompile common.Address, input []byte) ([]byte, bool) {
mu.RLock()
defer mu.RUnlock()
cache, ok := caches[precompile]
if !ok {
caches[precompile] = lru.NewCache[string, []byte](128)