Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

x/evm: (*Keeper).EthereumTx should use make(T, len) instead of make(T, 0) #825

Closed
odeke-em opened this issue Dec 11, 2021 · 0 comments · Fixed by #827
Closed

x/evm: (*Keeper).EthereumTx should use make(T, len) instead of make(T, 0) #825

odeke-em opened this issue Dec 11, 2021 · 0 comments · Fixed by #827

Comments

@odeke-em
Copy link
Contributor

Noticed while auditing code on the hunt for higher TPS, this code https://github.com/tharsis/ethermint/blob/54fa882ab8e56e3de65a1a730b02e73884c26bed/x/evm/keeper/msg_server.go#L55-L62

but if we examine perfclinic's verdict per https://bencher.orijtech.com/perfclinic/sliceupdate/#verdict and per https://bencher.orijtech.com/perfclinic/sliceupdate/#make-with-size-n-capacity-n

We should use an index with the size for that slice.

odeke-em added a commit that referenced this issue Dec 12, 2021
…x.Logs

Uses the fastest slice making idiom of creating the well known
size of a slice using

    make([]sdk.Attribute, len(response.Logs))
    for i, log := range response.Logs {
        txLogAttrs[i] = ...
    }

instead of

    make([]sdk.Attribute, 0)
    for _, log := range response.Logs {
        txLogAttrs = append(txLogAttrs, ...)
    }

which had a few problems:
1. Using 0 for size then appending is quite slow yet we know the exact size
2. Using append instead of indexing is slower

If we examine the advisory at https://bencher.orijtech.com/perfclinic/sliceupdate/
and the verdict at https://bencher.orijtech.com/perfclinic/sliceupdate/#verdict
this new scheme shows a massive improvement in that call site.

Fixes #825
odeke-em added a commit that referenced this issue Dec 14, 2021
…x.Logs

Uses the fastest slice making idiom of creating the well known
size of a slice using

    make([]sdk.Attribute, len(response.Logs))
    for i, log := range response.Logs {
        txLogAttrs[i] = ...
    }

instead of

    make([]sdk.Attribute, 0)
    for _, log := range response.Logs {
        txLogAttrs = append(txLogAttrs, ...)
    }

which had a few problems:
1. Using 0 for size then appending is quite slow yet we know the exact size
2. Using append instead of indexing is slower

If we examine the advisory at https://bencher.orijtech.com/perfclinic/sliceupdate/
and the verdict at https://bencher.orijtech.com/perfclinic/sliceupdate/#verdict
this new scheme shows a massive improvement in that call site.

Fixes #825
odeke-em added a commit that referenced this issue Dec 14, 2021
…x.Logs (#827)

Uses the fastest slice making idiom of creating the well known
size of a slice using

    make([]sdk.Attribute, len(response.Logs))
    for i, log := range response.Logs {
        txLogAttrs[i] = ...
    }

instead of

    make([]sdk.Attribute, 0)
    for _, log := range response.Logs {
        txLogAttrs = append(txLogAttrs, ...)
    }

which had a few problems:
1. Using 0 for size then appending is quite slow yet we know the exact size
2. Using append instead of indexing is slower

If we examine the advisory at https://bencher.orijtech.com/perfclinic/sliceupdate/
and the verdict at https://bencher.orijtech.com/perfclinic/sliceupdate/#verdict
this new scheme shows a massive improvement in that call site.

Fixes #825
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant