core/types: reduce allocations for transaction comparison#31912
Merged
MariusVanDerWijden merged 5 commits intoAug 22, 2025
Conversation
fjl
reviewed
May 28, 2025
cskiraly
reviewed
Aug 20, 2025
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
ba1d582 to
8bd1d31
Compare
Better check in case this is used as library. Not using MustFromBig as we don't have control over how this is being used. Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
Contributor
|
@MariusVanDerWijden I was adding overflow checks everywhere in case this is used in some other context. Not using MustFromBig to avod panic in those cases. Let me know if you agree. |
gballet
pushed a commit
to gballet/go-ethereum
that referenced
this pull request
Sep 11, 2025
…1912) This PR should reduce overall allocations of a running node by ~10 percent. Since most allocations are coming from the re-heaping of the transaction pool. ``` (pprof) list EffectiveGasTipCmp Total: 38197204475 ROUTINE ======================== github.com/ethereum/go-ethereum/core/types.(*Transaction).EffectiveGasTipCmp in github.com/ethereum/go-ethereum/core/types/transaction.go 0 3766837369 (flat, cum) 9.86% of Total . . 386:func (tx *Transaction) EffectiveGasTipCmp(other *Transaction, baseFee *big.Int) int { . . 387: if baseFee == nil { . . 388: return tx.GasTipCapCmp(other) . . 389: } . . 390: // Use more efficient internal method. . . 391: txTip, otherTip := new(big.Int), new(big.Int) . 1796172553 392: tx.calcEffectiveGasTip(txTip, baseFee) . 1970664816 393: other.calcEffectiveGasTip(otherTip, baseFee) . . 394: return txTip.Cmp(otherTip) . . 395:} . . 396: . . 397:// EffectiveGasTipIntCmp compares the effective gasTipCap of a transaction to the given gasTipCap. . . 398:func (tx *Transaction) EffectiveGasTipIntCmp(other *big.Int, baseFee *big.Int) int { ``` This PR reduces the allocations for comparing two transactions from 2 to 0: ``` goos: linux goarch: amd64 pkg: github.com/ethereum/go-ethereum/core/types cpu: Intel(R) Core(TM) Ultra 7 155U │ /tmp/old.txt │ /tmp/new.txt │ │ sec/op │ sec/op vs base │ EffectiveGasTipCmp/Original-14 64.67n ± 2% 25.13n ± 9% -61.13% (p=0.000 n=10) │ /tmp/old.txt │ /tmp/new.txt │ │ B/op │ B/op vs base │ EffectiveGasTipCmp/Original-14 16.00 ± 0% 0.00 ± 0% -100.00% (p=0.000 n=10) │ /tmp/old.txt │ /tmp/new.txt │ │ allocs/op │ allocs/op vs base │ EffectiveGasTipCmp/Original-14 2.000 ± 0% 0.000 ± 0% -100.00% (p=0.000 n=10) ``` It also speeds up the process by ~60% There are two minor caveats with this PR: - We change the API for `EffectiveGasTipCmp` and `EffectiveGasTipIntCmp` (which are probably not used by much) - We slightly change the behavior of `tx.EffectiveGasTip` when it returns an error. It would previously return a negative number on error, now it does not (since uint256 does not allow for negative numbers) --------- Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com> Co-authored-by: Csaba Kiraly <csaba.kiraly@gmail.com>
gzliudan
added a commit
to gzliudan/XDPoSChain
that referenced
this pull request
Mar 19, 2026
25 tasks
gzliudan
added a commit
to gzliudan/XDPoSChain
that referenced
this pull request
Mar 19, 2026
gzliudan
added a commit
to gzliudan/XDPoSChain
that referenced
this pull request
Mar 19, 2026
gzliudan
added a commit
to gzliudan/XDPoSChain
that referenced
this pull request
Mar 19, 2026
gzliudan
added a commit
to gzliudan/XDPoSChain
that referenced
this pull request
Mar 20, 2026
gzliudan
added a commit
to gzliudan/XDPoSChain
that referenced
this pull request
Mar 24, 2026
gzliudan
added a commit
to gzliudan/XDPoSChain
that referenced
this pull request
Mar 24, 2026
AnilChinchawale
pushed a commit
to XinFinOrg/XDPoSChain
that referenced
this pull request
Mar 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR should reduce overall allocations of a running node by ~10 percent. Since most allocations are coming from the re-heaping of the transaction pool.
This PR reduces the allocations for comparing two transactions from 2 to 0:
It also speeds up the process by ~60%
There are two minor caveats with this PR:
EffectiveGasTipCmpandEffectiveGasTipIntCmp(which are probably not used by much)tx.EffectiveGasTipwhen it returns an error. It would previously return a negative number on error, now it does not (since uint256 does not allow for negative numbers)