x/evm/keeper: save 24B with Go in-condition variable idiom (#828)

* x/evm/keeper: save 24B with Go in-condition variable idiom

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

* changelog

* lint

* Revert stray changes that were used in testing

* rm log

Co-authored-by: Federico Kunze Küllmer <federico.kunze94@gmail.com>
This commit is contained in:
Emmanuel T Odeke 2021-12-13 15:51:36 -08:00 committed by GitHub
parent 876d9cfee3
commit 8333765b27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 8 additions and 23 deletions

View File

@ -28,7 +28,7 @@ linters:
- staticcheck - staticcheck
- structcheck - structcheck
- stylecheck - stylecheck
- typecheck # - typecheck #TODO: enable
- unconvert - unconvert
- unparam - unparam
- unused - unused

View File

@ -37,6 +37,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
## Unreleased ## Unreleased
### Improvements
* (evm) [tharsis#826](https://github.com/tharsis/ethermint/issues/826) Improve allocation of bytes of `tx.To` address.
## [v0.9.0] - 2021-12-01 ## [v0.9.0] - 2021-12-01
### State Machine Breaking ### State Machine Breaking

View File

@ -1,16 +0,0 @@
{
"Linters": {
"vet": "go tool vet -composites=false :PATH:LINE:MESSAGE"
},
"Enable": [
"golint",
"vet",
"ineffassign",
"unparam",
"unconvert",
"misspell"
],
"Deadline": "500s",
"Vendor": true,
"Cyclo": 11
}

View File

@ -41,8 +41,6 @@ import (
storetypes "github.com/cosmos/cosmos-sdk/store/types" storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
ethlog "github.com/ethereum/go-ethereum/log"
"github.com/tharsis/ethermint/log"
ethdebug "github.com/tharsis/ethermint/rpc/ethereum/namespaces/debug" ethdebug "github.com/tharsis/ethermint/rpc/ethereum/namespaces/debug"
"github.com/tharsis/ethermint/server/config" "github.com/tharsis/ethermint/server/config"
srvflags "github.com/tharsis/ethermint/server/flags" srvflags "github.com/tharsis/ethermint/server/flags"
@ -405,12 +403,11 @@ func startInProcess(ctx *server.Context, clientCtx client.Context, appCreator ty
} }
} }
ethlog.Root().SetHandler(log.NewHandler(logger))
var ( var (
httpSrv *http.Server httpSrv *http.Server
httpSrvDone chan struct{} httpSrvDone chan struct{}
) )
if config.JSONRPC.Enable { if config.JSONRPC.Enable {
genDoc, err := genDocProvider() genDoc, err := genDocProvider()
if err != nil { if err != nil {

View File

@ -44,8 +44,8 @@ func (k *Keeper) EthereumTx(goCtx context.Context, msg *types.MsgEthereumTx) (*t
attrs = append(attrs, sdk.NewAttribute(types.AttributeKeyTxHash, hash.String())) attrs = append(attrs, sdk.NewAttribute(types.AttributeKeyTxHash, hash.String()))
} }
if tx.To() != nil { if to := tx.To(); to != nil {
attrs = append(attrs, sdk.NewAttribute(types.AttributeKeyRecipient, tx.To().Hex())) attrs = append(attrs, sdk.NewAttribute(types.AttributeKeyRecipient, to.Hex()))
} }
if response.Failed() { if response.Failed() {