mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-03-18 00:50:39 +00:00
core/state: avoid Bytes() allocation in flatReader hash computations (#34025)
## Summary Replace `addr.Bytes()` and `key.Bytes()` with `addr[:]` and `key[:]` in `flatReader`'s `Account` and `Storage` methods. The former allocates a copy while the latter creates a zero-allocation slice header over the existing backing array. ## Benchmark (AMD EPYC 48-core, 500K entries, screening `--benchtime=1x`) | Metric | Baseline | Slice syntax | Delta | |--------|----------|--------------|-------| | Approve (Mgas/s) | 4.13 | 4.22 | +2.2% | | BalanceOf (Mgas/s) | 168.3 | 190.0 | **+12.9%** |
This commit is contained in:
parent
98b13f342f
commit
4b915af2c3
1 changed files with 3 additions and 3 deletions
|
|
@ -98,7 +98,7 @@ func newFlatReader(reader database.StateReader) *flatReader {
|
|||
//
|
||||
// The returned account might be nil if it's not existent.
|
||||
func (r *flatReader) Account(addr common.Address) (*types.StateAccount, error) {
|
||||
account, err := r.reader.Account(crypto.Keccak256Hash(addr.Bytes()))
|
||||
account, err := r.reader.Account(crypto.Keccak256Hash(addr[:]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -128,8 +128,8 @@ func (r *flatReader) Account(addr common.Address) (*types.StateAccount, error) {
|
|||
//
|
||||
// The returned storage slot might be empty if it's not existent.
|
||||
func (r *flatReader) Storage(addr common.Address, key common.Hash) (common.Hash, error) {
|
||||
addrHash := crypto.Keccak256Hash(addr.Bytes())
|
||||
slotHash := crypto.Keccak256Hash(key.Bytes())
|
||||
addrHash := crypto.Keccak256Hash(addr[:])
|
||||
slotHash := crypto.Keccak256Hash(key[:])
|
||||
ret, err := r.reader.Storage(addrHash, slotHash)
|
||||
if err != nil {
|
||||
return common.Hash{}, err
|
||||
|
|
|
|||
Loading…
Reference in a new issue