-
Notifications
You must be signed in to change notification settings - Fork 86
perf(levm): improve codecopy #3497
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
Changes from 5 commits
10311b8
2f78a22
db3c13f
62ce6b9
0b7337b
c1a74e2
aa1572c
d2c5ef2
74db41c
7581e70
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -210,27 +210,49 @@ impl<'a> VM<'a> { | |
return Ok(OpcodeResult::Continue { pc_increment: 1 }); | ||
} | ||
|
||
let mut data = vec![0u8; size]; | ||
// Here we verified indexing is in bounds. | ||
#[expect(clippy::indexing_slicing, clippy::arithmetic_side_effects)] | ||
if code_offset < current_call_frame.bytecode.len().into() { | ||
let code_offset: usize = code_offset | ||
.try_into() | ||
.map_err(|_| InternalError::TypeConversion)?; | ||
|
||
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; | ||
} | ||
Comment on lines
-219
to
-228
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm curious: did we try changing this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We would always allocate a vec then, this would depend heavily on the bench, if we do small sized and repeated codecopies the stack fixed size array will be faster. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The project already imports |
||
let available = size.min( | ||
current_call_frame | ||
.bytecode | ||
.len() | ||
.saturating_sub(code_offset), | ||
); | ||
|
||
if size <= 32 { | ||
let mut data = [0u8; 32]; | ||
|
||
data[..available].copy_from_slice( | ||
¤t_call_frame.bytecode[code_offset..code_offset + available], | ||
); | ||
|
||
memory::try_store_data( | ||
&mut current_call_frame.memory, | ||
destination_offset, | ||
&data[..size], | ||
)?; | ||
} else { | ||
let mut data = vec![0u8; size]; | ||
|
||
data[..available].copy_from_slice( | ||
¤t_call_frame.bytecode[code_offset..code_offset + available], | ||
); | ||
|
||
memory::try_store_data(&mut current_call_frame.memory, destination_offset, &data)?; | ||
} | ||
} else { | ||
memory::try_store_data( | ||
&mut current_call_frame.memory, | ||
destination_offset, | ||
&vec![0u8; size], | ||
)?; | ||
} | ||
|
||
memory::try_store_data(&mut current_call_frame.memory, destination_offset, &data)?; | ||
|
||
Ok(OpcodeResult::Continue { pc_increment: 1 }) | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.