Skip to content

perf(levm): codecopy perf improvement #3675

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

Merged
merged 51 commits into from
Jul 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
2680471
new memory progress
edg-l Jul 8, 2025
4a01b9e
done
edg-l Jul 8, 2025
e7c80b7
Merge branch 'main' into new_memory
edg-l Jul 8, 2025
4387a0c
fix
edg-l Jul 8, 2025
2fa2694
fix
edg-l Jul 8, 2025
a7c23fe
improve
edg-l Jul 8, 2025
ee33f25
Merge branch 'main' into new_memory
edg-l Jul 9, 2025
62ef32f
better
edg-l Jul 9, 2025
8f5ed9d
fix mcopy
edg-l Jul 9, 2025
b44d5bc
fill instead of truncate
edg-l Jul 9, 2025
f253bab
remove dbg
edg-l Jul 9, 2025
72e08b6
fix
edg-l Jul 9, 2025
74a289a
better handling
edg-l Jul 9, 2025
7a4f252
improve
edg-l Jul 9, 2025
cb33cee
fix and better perf
edg-l Jul 10, 2025
de4520d
Merge remote-tracking branch 'origin/main' into new_memory
edg-l Jul 10, 2025
87a255b
Merge branch 'main' into new_memory
edg-l Jul 14, 2025
37d71b8
fixes
edg-l Jul 14, 2025
f8a0c49
changelog
edg-l Jul 14, 2025
a710c04
remove unused
edg-l Jul 14, 2025
1ba46a3
rename
edg-l Jul 14, 2025
9de7221
docs
edg-l Jul 14, 2025
b11af48
remove unwraps
edg-l Jul 14, 2025
ace118c
better
edg-l Jul 14, 2025
5e7efd3
improve
edg-l Jul 14, 2025
34d4474
force inline to improve perfomance
edg-l Jul 14, 2025
2a97377
unsafe
edg-l Jul 14, 2025
10df4fb
more unsafe
edg-l Jul 14, 2025
47cfc11
unsafe
edg-l Jul 14, 2025
b025e3d
fmt
edg-l Jul 14, 2025
e22d55b
better
edg-l Jul 14, 2025
f022b08
inline
edg-l Jul 14, 2025
5dbfd83
improve
edg-l Jul 15, 2025
beed672
more
edg-l Jul 15, 2025
981da2c
experimental
edg-l Jul 15, 2025
4d67f60
Merge branch 'main' into new_memory
edg-l Jul 15, 2025
d54da5b
Merge remote-tracking branch 'origin/new_memory' into new_memory_unsa…
edg-l Jul 15, 2025
b0aad27
Merge branch 'main' into new_memory
edg-l Jul 15, 2025
4299eb0
Merge branch 'main' into new_memory
edg-l Jul 15, 2025
44a4a3f
Merge branch 'main' into new_memory
edg-l Jul 16, 2025
f332dd1
Merge branch 'main' into new_memory
edg-l Jul 16, 2025
3f5f604
Merge branch 'main' into new_memory
edg-l Jul 16, 2025
4316cf0
Merge branch 'main' into new_memory
edg-l Jul 17, 2025
93373ad
comments
edg-l Jul 17, 2025
f33d78c
format
edg-l Jul 17, 2025
1298156
Merge branch 'main' into new_memory
edg-l Jul 17, 2025
38246b4
codecopy improvement
edg-l Jul 17, 2025
5619278
changelog
edg-l Jul 17, 2025
48ee3bf
Merge remote-tracking branch 'origin/main' into codecopy_perf_improve…
edg-l Jul 17, 2025
6d3cd72
Merge branch 'main' into codecopy_perf_improvement
edg-l Jul 18, 2025
344cf80
prettier
edg-l Jul 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

### 2025-07-17

- Improve CodeCopy perfomance [#3675](https://github.com/lambdaclass/ethrex/pull/3675)

- Improve sstore perfomance further [#3657](https://github.com/lambdaclass/ethrex/pull/3657)

### 2025-07-16

- Improve levm memory model [#3564](https://github.com/lambdaclass/ethrex/pull/3564)
-

### 2025-07-15

- Add sstore bench [#3552](https://github.com/lambdaclass/ethrex/pull/3552)
Expand Down
35 changes: 25 additions & 10 deletions crates/vm/levm/src/opcode_handlers/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,18 +226,33 @@ impl<'a> VM<'a> {
return Ok(OpcodeResult::Continue { pc_increment: 1 });
}

// Happiest fast path, copy without an intermediate buffer because there is no need to pad 0s and also size doesn't overflow.
if let Some(code_offset_end) = code_offset.checked_add(size) {
if code_offset_end < current_call_frame.bytecode.len() {
#[expect(unsafe_code, reason = "bounds checked beforehand")]
let slice = unsafe {
current_call_frame
.bytecode
.get_unchecked(code_offset..code_offset_end)
};
current_call_frame
.memory
.store_data(destination_offset, slice)?;

return Ok(OpcodeResult::Continue { pc_increment: 1 });
}
}

let mut data = vec![0u8; size];
if code_offset < current_call_frame.bytecode.len() {
for (i, byte) in current_call_frame
.bytecode
.iter()
.skip(code_offset)
.take(size)
.enumerate()
{
if let Some(data_byte) = data.get_mut(i) {
*data_byte = *byte;
}
let diff = current_call_frame.bytecode.len().wrapping_sub(code_offset);
let final_size = size.min(diff);
let end = code_offset.wrapping_add(final_size);

#[expect(unsafe_code, reason = "bounds checked beforehand")]
unsafe {
data.get_unchecked_mut(..final_size)
.copy_from_slice(current_call_frame.bytecode.get_unchecked(code_offset..end));
}
}

Expand Down
Loading