Skip to content

core/types: Add allocation-free EffectiveGasTipInto method #31598

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SatoshiIsHere
Copy link
Contributor

This PR introduces an allocation-free version of the Transaction.EffectiveGasTip method to improve performance by reducing memory allocations.

Changes

  • Added a new EffectiveGasTipInto method that accepts a destination parameter to avoid memory allocations
  • Refactored the existing EffectiveGasTip method to use the new allocation-free implementation
  • Updated related methods (EffectiveGasTipValue, EffectiveGasTipCmp, EffectiveGasTipIntCmp) to use the allocation-free approach
  • Added tests and benchmarks to verify correctness and measure performance improvements

Motivation

In high-transaction-volume environments, the EffectiveGasTip method is called frequently. Reducing memory allocations in this method decreases garbage collection pressure and improves overall system performance.

Benchmark Results

As-Is
BenchmarkEffectiveGasTip/Original-10 42089140 27.45 ns/op 8 B/op 1 allocs/op

To-Be
BenchmarkEffectiveGasTip/IntoMethod-10 72353263 16.73 ns/op 0 B/op 0 allocs/op

Summary of Improvements

  • Performance: ~39% faster execution (27.45 ns/op → 16.73 ns/op)
  • Memory: Eliminated all allocations (8 B/op → 0 B/op)
  • Allocation count: Reduced from 1 to 0 allocations per operation

This optimization follows the same pattern successfully applied to other methods in the codebase, maintaining API compatibility while improving performance.

Safety & Compatibility

This optimization has no side effects or adverse impacts because:

  • It maintains functional equivalence as confirmed by comprehensive tests
  • It preserves API compatibility with existing callers
  • It follows clear memory ownership patterns with the destination parameter
  • It maintains thread safety by only modifying the caller-provided destination parameter

This optimization follows the same pattern successfully applied to other methods in the codebase, providing better performance without compromising stability or correctness.

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.

1 participant