Skip to content

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.

Copy link
Member

@MariusVanDerWijden MariusVanDerWijden left a comment

Choose a reason for hiding this comment

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

Two small nits, otherwise looks good. I closed my similar PR in favor of this

@SatoshiIsHere SatoshiIsHere requested a review from s1na as a code owner April 22, 2025 14:43
Copy link
Member

@MariusVanDerWijden MariusVanDerWijden left a comment

Choose a reason for hiding this comment

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

LGTM

@MariusVanDerWijden MariusVanDerWijden added this to the 1.15.10 milestone Apr 23, 2025
@fjl fjl modified the milestones: 1.15.10, 1.15.11 Apr 25, 2025
@fjl fjl modified the milestones: 1.15.11, 1.15.12 May 5, 2025
Copy link
Member

@lightclient lightclient left a comment

Choose a reason for hiding this comment

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

Made a small rename of the internal method, LGTM though.

@MariusVanDerWijden MariusVanDerWijden changed the title core/types: Add allocation-free EffectiveGasTipInto method core/types: reduce allocations in tx.EffectiveGasTip May 9, 2025
@MariusVanDerWijden MariusVanDerWijden merged commit 0db99f4 into ethereum:master May 9, 2025
2 of 4 checks passed
howjmay pushed a commit to iotaledger/go-ethereum that referenced this pull request Aug 27, 2025
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.

---------

Co-authored-by: lightclient <[email protected]>
gballet pushed a commit to gballet/go-ethereum that referenced this pull request Sep 11, 2025
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.

---------

Co-authored-by: lightclient <[email protected]>
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