Skip to content

Optimize Transaction Pool Gas Tip Comparison#3120

Merged
zzzckck merged 1 commit intodevelopfrom
trx-estimation-allocation
May 28, 2025
Merged

Optimize Transaction Pool Gas Tip Comparison#3120
zzzckck merged 1 commit intodevelopfrom
trx-estimation-allocation

Conversation

@MatusKysel
Copy link
Copy Markdown
Contributor

@MatusKysel MatusKysel commented May 26, 2025

Optimize Transaction Pool Gas Tip Comparison

Description

This PR optimizes the EffectiveGasTipCmp function in the transaction pool by removing an unnecessary allocation. The function compares the effective gas tips of two transactions, which is used for transaction ordering in the pool.

Changes

  • Refactored EffectiveGasTipCmp to avoid creating new big.Int allocations
  • Added detailed documentation explaining the effective gas tip calculation
  • Improved code readability by breaking down the comparison logic into clear steps

Technical Details

The effective gas tip is calculated as the minimum of:

  1. The transaction's gasTipCap
  2. The transaction's gasFeeCap minus the base fee

The previous implementation created new big.Int allocations through EffectiveGasTipValue() calls. The new implementation performs the calculations directly using the existing big.Int values, eliminating these allocations.

Impact

  • Reduced memory allocations in the transaction pool
  • Improved performance for transaction ordering operations
  • No functional changes to the transaction pool behavior
Screenshot 2025-05-21 at 13 33 38

@MatusKysel MatusKysel requested a review from Copilot May 26, 2025 09:36
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the EffectiveGasTipCmp function in transaction.go to remove an unnecessary allocation by inlining the gas tip comparison logic.

  • Removed reliance on EffectiveGasTipValue to avoid extra allocation.
  • Introduced manual subtraction and minimum value comparisons for gas fee and gas tip caps.
Comments suppressed due to low confidence (1)

core/types/transaction.go:409

  • Ensure that tx.GasFeeCap() returns a fresh instance and does not reuse an internal value, since calling Sub() modifies its receiver. If there's a risk of side effects, consider using new(big.Int).Sub(tx.GasFeeCap(), baseFee) to preserve internal state.
txGasFeeCap = txGasFeeCap.Sub(txGasFeeCap, baseFee)

@MatusKysel MatusKysel changed the title tx_pool: remove one non-necessary allocation Optimize Transaction Pool Gas Tip Comparison May 26, 2025
@MatusKysel MatusKysel requested review from buddh0, galaio and zzzckck May 26, 2025 09:43

// Get gas tip caps
txGasTipCap := tx.inner.gasTipCap()
otherGasTipCap := other.inner.gasTipCap()
Copy link
Copy Markdown
Collaborator

@zzzckck zzzckck May 28, 2025

Choose a reason for hiding this comment

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

approved.
here reduces 2 allocations of new(big.Int) comparing to call GasTipCap() directly.

@zzzckck zzzckck merged commit c59a460 into develop May 28, 2025
7 checks passed
@MatusKysel MatusKysel deleted the trx-estimation-allocation branch February 17, 2026 17:31
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.

4 participants