core/vm: global cache for jumpdest bitmaps

This commit is contained in:
Sina Mahmoodi 2026-04-29 16:44:09 +02:00
parent a065580422
commit faef2454fc
2 changed files with 29 additions and 2 deletions

View file

@ -140,7 +140,7 @@ func NewEVM(blockCtx BlockContext, statedb StateDB, chainConfig *params.ChainCon
Config: config,
chainConfig: chainConfig,
chainRules: chainConfig.Rules(blockCtx.BlockNumber, blockCtx.Random != nil, blockCtx.Time),
jumpDests: newMapJumpDests(),
jumpDests: newGlobalJumpDests(),
}
evm.precompiles = activePrecompiledContracts(evm.chainRules)

View file

@ -16,7 +16,11 @@
package vm
import "github.com/ethereum/go-ethereum/common"
import (
"sync"
"github.com/ethereum/go-ethereum/common"
)
// JumpDestCache represents the cache of jumpdest analysis results.
type JumpDestCache interface {
@ -45,3 +49,26 @@ func (j mapJumpDests) Load(codeHash common.Hash) (BitVec, bool) {
func (j mapJumpDests) Store(codeHash common.Hash, vec BitVec) {
j[codeHash] = vec
}
// globalJumpDestCache is a global cache of JUMPDEST bitmaps.
var globalJumpDestCache sync.Map
type globalJumpDests struct{}
// newGlobalJumpDests returns a JumpDestCache backed by the process-global
// sync.Map. All callers share the same backing map.
func newGlobalJumpDests() JumpDestCache {
return globalJumpDests{}
}
func (globalJumpDests) Load(codeHash common.Hash) (BitVec, bool) {
v, ok := globalJumpDestCache.Load(codeHash)
if !ok {
return nil, false
}
return v.(BitVec), true
}
func (globalJumpDests) Store(codeHash common.Hash, vec BitVec) {
globalJumpDestCache.Store(codeHash, vec)
}