Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core/types: reduce allocations in GasPriceCmp #22456

Merged
merged 1 commit into from
Mar 8, 2021

Conversation

MariusVanDerWijden
Copy link
Member

Current master allocates a lot of unnecessary big integers when comparing gas prices.
Since the tx_list (part of the txpool) relies heavily on comparing transactions by gas price, this does ~1.6% of all allocations unnecessarily.
This PR directly compares the inner gas prices without creating a new big int in the process

Total: 479893007
ROUTINE ======================== github.com/ethereum/go-ethereum/core/types.(*Transaction).GasPrice in github.com/ethereum/go-ethereum/core/types/transaction.go
  10764599   15876467 (flat, cum)  3.31% of Total
         .          .    256:
         .          .    257:// Gas returns the gas limit of the transaction.
         .          .    258:func (tx *Transaction) Gas() uint64 { return tx.inner.gas() }
         .          .    259:
         .          .    260:// GasPrice returns the gas price of the transaction.
  10764599   15876467    261:func (tx *Transaction) GasPrice() *big.Int { return new(big.Int).Set(tx.inner.gasPrice()) }
         .          .    262:
         .          .    263:// Value returns the ether amount of the transaction.
         .          .    264:func (tx *Transaction) Value() *big.Int { return new(big.Int).Set(tx.inner.value()) }
         .          .    265:
         .          .    266:// Nonce returns the sender account nonce of the transaction.
ROUTINE ======================== github.com/ethereum/go-ethereum/core/types.(*Transaction).GasPriceCmp in github.com/ethereum/go-ethereum/core/types/transaction.go
         0    7717050 (flat, cum)  1.61% of Total
         .          .    291:   return tx.inner.rawSignatureValues()
         .          .    292:}
         .          .    293:
         .          .    294:// GasPriceCmp compares the gas prices of two transactions.
         .          .    295:func (tx *Transaction) GasPriceCmp(other *Transaction) int {
         .    7717050    296:   return tx.inner.gasPrice().Cmp(other.GasPrice())
         .          .    297:}
         .          .    298:
         .          .    299:// GasPriceIntCmp compares the gas price of the transaction against the given price.
         .          .    300:func (tx *Transaction) GasPriceIntCmp(other *big.Int) int {
         .          .    301:   return tx.inner.gasPrice().Cmp(other)

Copy link
Contributor

@holiman holiman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@karalabe karalabe added this to the 1.10.2 milestone Mar 8, 2021
@karalabe karalabe merged commit be87f76 into ethereum:master Mar 8, 2021
atif-konasl pushed a commit to frozeman/pandora-execution-engine that referenced this pull request Oct 15, 2021
@MariusVanDerWijden MariusVanDerWijden deleted the tx-reduce-allocs branch November 30, 2021 15:25
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants