mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
core: precompute precompiles in create evm instead of compute it each time
name old time/op new time/op delta SimpleLoop/staticcall-identity-100M-10 134ms ± 1% 131ms ± 0% -2.60% (p=0.000 n=17+18) SimpleLoop/call-identity-100M-10 158ms ± 1% 157ms ± 2% -1.00% (p=0.000 n=20+20) SimpleLoop/loop-100M-10 200ms ± 1% 197ms ± 1% -1.43% (p=0.000 n=16+19) SimpleLoop/call-nonexist-100M-10 504ms ± 0% 508ms ± 0% +0.82% (p=0.000 n=16+20) SimpleLoop/call-EOA-100M-10 147ms ± 2% 148ms ± 4% ~ (p=0.060 n=20+20) SimpleLoop/call-reverting-100M-10 330ms ± 0% 329ms ± 0% -0.30% (p=0.003 n=18+16) name old alloc/op new alloc/op delta SimpleLoop/staticcall-identity-100M-10 21.9MB ± 0% 21.9MB ± 0% ~ (p=0.219 n=20+20) SimpleLoop/call-identity-100M-10 21.5MB ± 0% 21.5MB ± 0% ~ (p=0.140 n=20+20) SimpleLoop/loop-100M-10 2.73kB ±13% 2.70kB ±14% ~ (p=0.764 n=20+20) SimpleLoop/call-nonexist-100M-10 102MB ± 0% 102MB ± 0% ~ (p=0.723 n=20+20) SimpleLoop/call-EOA-100M-10 23.9MB ± 0% 23.9MB ± 0% ~ (p=0.797 n=20+19) SimpleLoop/call-reverting-100M-10 240MB ± 0% 240MB ± 0% ~ (p=0.409 n=18+20) name old allocs/op new allocs/op delta SimpleLoop/staticcall-identity-100M-10 685k ± 0% 685k ± 0% ~ (p=0.146 n=20+20) SimpleLoop/call-identity-100M-10 671k ± 0% 671k ± 0% ~ (p=0.221 n=20+20) SimpleLoop/loop-100M-10 26.6 ± 5% 26.5 ± 6% ~ (p=1.000 n=20+20) SimpleLoop/call-nonexist-100M-10 2.24M ± 0% 2.24M ± 0% ~ (p=0.973 n=20+20) SimpleLoop/call-EOA-100M-10 746k ± 0% 746k ± 0% ~ (p=0.947 n=20+20) SimpleLoop/call-reverting-100M-10 5.00M ± 0% 5.00M ± 0% ~ (p=0.225 n=18+20)
This commit is contained in:
parent
b9ca38b735
commit
54498a3504
1 changed files with 21 additions and 15 deletions
|
|
@ -38,20 +38,7 @@ type (
|
|||
)
|
||||
|
||||
func (evm *EVM) precompile(addr common.Address) (PrecompiledContract, bool) {
|
||||
var precompiles map[common.Address]PrecompiledContract
|
||||
switch {
|
||||
case evm.chainRules.IsCancun:
|
||||
precompiles = PrecompiledContractsCancun
|
||||
case evm.chainRules.IsBerlin:
|
||||
precompiles = PrecompiledContractsBerlin
|
||||
case evm.chainRules.IsIstanbul:
|
||||
precompiles = PrecompiledContractsIstanbul
|
||||
case evm.chainRules.IsByzantium:
|
||||
precompiles = PrecompiledContractsByzantium
|
||||
default:
|
||||
precompiles = PrecompiledContractsHomestead
|
||||
}
|
||||
p, ok := precompiles[addr]
|
||||
p, ok := evm.precompiles[addr]
|
||||
return p, ok
|
||||
}
|
||||
|
||||
|
|
@ -121,6 +108,8 @@ type EVM struct {
|
|||
// available gas is calculated in gasCall* according to the 63/64 rule and later
|
||||
// applied in opCall*.
|
||||
callGasTemp uint64
|
||||
|
||||
precompiles map[common.Address]PrecompiledContract
|
||||
}
|
||||
|
||||
// NewEVM returns a new EVM. The returned EVM is not thread safe and should
|
||||
|
|
@ -137,13 +126,30 @@ func NewEVM(blockCtx BlockContext, txCtx TxContext, statedb StateDB, chainConfig
|
|||
blockCtx.BlobBaseFee = new(big.Int)
|
||||
}
|
||||
}
|
||||
|
||||
chainRules := chainConfig.Rules(blockCtx.BlockNumber, blockCtx.Random != nil, blockCtx.Time)
|
||||
var precompiles map[common.Address]PrecompiledContract
|
||||
switch {
|
||||
case chainRules.IsCancun:
|
||||
precompiles = PrecompiledContractsCancun
|
||||
case chainRules.IsBerlin:
|
||||
precompiles = PrecompiledContractsBerlin
|
||||
case chainRules.IsIstanbul:
|
||||
precompiles = PrecompiledContractsIstanbul
|
||||
case chainRules.IsByzantium:
|
||||
precompiles = PrecompiledContractsByzantium
|
||||
default:
|
||||
precompiles = PrecompiledContractsHomestead
|
||||
}
|
||||
|
||||
evm := &EVM{
|
||||
Context: blockCtx,
|
||||
TxContext: txCtx,
|
||||
StateDB: statedb,
|
||||
Config: config,
|
||||
chainConfig: chainConfig,
|
||||
chainRules: chainConfig.Rules(blockCtx.BlockNumber, blockCtx.Random != nil, blockCtx.Time),
|
||||
chainRules: chainRules,
|
||||
precompiles: precompiles,
|
||||
}
|
||||
evm.interpreter = NewEVMInterpreter(evm)
|
||||
return evm
|
||||
|
|
|
|||
Loading…
Reference in a new issue