Skip to content

Comments

perf: add optimization for push and pop#3263

Merged
rakita merged 6 commits intobluealloy:mainfrom
malik672:holiday
Jan 5, 2026
Merged

perf: add optimization for push and pop#3263
rakita merged 6 commits intobluealloy:mainfrom
malik672:holiday

Conversation

@malik672
Copy link
Contributor

@malik672 malik672 commented Dec 30, 2025

make push 5.4x faster
Pop not much changes but we can add likely and unlikely instrincts

https://godbolt.org/z/8a5GKj4WT

@codspeed-hq
Copy link

codspeed-hq bot commented Dec 30, 2025

CodSpeed Performance Report

Merging #3263 will degrade performance by 3.46%

Comparing malik672:holiday (bd914b5) with main (fd8d920)

Summary

⚡ 7 improvements
❌ 1 regression
✅ 165 untouched

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Efficiency
ADDRESS_50 19.4 µs 18.8 µs +3.03%
CALLER_50 19.3 µs 18.7 µs +3.35%
GASPRICE_50 19.4 µs 18.8 µs +3.19%
COINBASE_50 19.4 µs 18.7 µs +3.67%
DIFFICULTY_50 19.6 µs 18.8 µs +4.24%
ORIGIN_50 19.2 µs 18.7 µs +3.04%
TIMESTAMP_50 19.1 µs 18.5 µs +3.25%
transact_commit_1000txs 3.2 ms 3.3 ms -3.46%

let end = self.data.as_mut_ptr().add(len);
core::ptr::write(end, value);
self.data.set_len(len + 1);
}
Copy link
Member

Choose a reason for hiding this comment

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

This is nice! we didn't optimize this function as it is not used that much, PUSH opcodes use optimized push_slice

#[cfg_attr(debug_assertions, track_caller)]
pub fn push(&mut self, value: U256) -> bool {
// In debug builds, verify we have sufficient capacity provisioned.
debug_assert!(self.data.capacity() >= STACK_LIMIT);
Copy link
Member

@rakita rakita Dec 30, 2025

Choose a reason for hiding this comment

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

It looks there was a bug here

Suggested change
debug_assert!(self.data.capacity() >= STACK_LIMIT);
debug_assert!(self.data.capacity() > STACK_LIMIT);

Capacity equal to STACK_LIMIT is checked in the line below.

Copy link
Contributor Author

@malik672 malik672 Dec 30, 2025

Choose a reason for hiding this comment

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

Mistake, it's meant to be assume

Copy link
Member

Choose a reason for hiding this comment

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

Will revert this line, it was correct previously. assume would not do anything here as we are handling pointers.

Copy link
Member

@rakita rakita left a comment

Choose a reason for hiding this comment

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

lgtm, merging after CI

perf degradation is about hashmap, so this PR does not touch this, it looks like hashmap/hasher is flaky.

@rakita rakita merged commit 191e2e3 into bluealloy:main Jan 5, 2026
30 of 31 checks passed
@github-actions github-actions bot mentioned this pull request Jan 5, 2026
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.

2 participants