x/evm/keeper: save 24B with Go in-condition variable idiom by odeke-em · Pull Request #828 · evmos/ethermint

The prior code doubly invoked (*ethereum/go-ethereum/core/types.Transaction).To()
which is quite expensive, and firstly copies 20 bytes each time, then
that gets rounded up to the proper size class/pointer alignment so on
64-bit machines 20B -> 24B.

Isolating a benchmark for this code per issue #826 shows this saves
quite a bit of bytes and some nano seconds which all count up towards
the transactions per seconds being processed:

```shell
$ benchstat before.txt after.txt
name        old time/op    new time/op    delta
CopyAddr-8    38.4ns ± 3%    19.3ns ± 3%  -49.66%  (p=0.000 n=10+10)

name        old alloc/op   new alloc/op   delta
CopyAddr-8     48.0B ± 0%     24.0B ± 0%  -50.00%  (p=0.000 n=10+10)

name        old allocs/op  new allocs/op  delta
CopyAddr-8      2.00 ± 0%      1.00 ± 0%  -50.00%  (p=0.000 n=10+10)
```

Fixes #826

@fedekunze @odeke-em

@fedekunze @odeke-em

@odeke-em

@fedekunze

fedekunze

@fedekunze fedekunze deleted the evm-keeper-singly-create-To-save-24B branch

December 13, 2021 23:51

odeke-em added a commit that referenced this pull request

Dec 14, 2021
Following suit with PR #828, this change cuts down the expenses
from using .To doubly; yet using the Go in-condition variable idiom.

Updates #826

odeke-em added a commit that referenced this pull request

Dec 14, 2021
Following suit with PR #828, this change cuts down the expenses
from using .To doubly; yet using the Go in-condition variable idiom.

Updates #826