Skip to content
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

perf: store code in Bytes #13

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ keywords = ["no_std", "ethereum"]
edition = "2018"

[dependencies]
bytes = { version = "1", default-features = false }
primitive-types = { version = "0.10", default-features = false }
codec = { package = "parity-scale-codec", version = "2.0", default-features = false, features = ["derive", "full"], optional = true }
serde = { version = "1.0", default-features = false, features = ["derive"], optional = true }
Expand Down
10 changes: 3 additions & 7 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub use crate::valids::Valids;
use crate::eval::{eval, Control};
use alloc::rc::Rc;
use alloc::vec::Vec;
use bytes::Bytes;
use core::ops::Range;
use primitive_types::{H160, U256};

Expand All @@ -32,7 +33,7 @@ pub struct Machine {
/// Program data.
data: Rc<Vec<u8>>,
/// Program code.
code: Rc<Vec<u8>>,
code: Bytes,
/// Program counter.
position: Result<usize, ExitReason>,
/// Return value.
Expand Down Expand Up @@ -86,12 +87,7 @@ impl Machine {
}

/// Create a new machine with given code and data.
pub fn new(
code: Rc<Vec<u8>>,
data: Rc<Vec<u8>>,
stack_limit: usize,
memory_limit: usize,
) -> Self {
pub fn new(code: Bytes, data: Rc<Vec<u8>>, stack_limit: usize, memory_limit: usize) -> Self {
let valids = Valids::new(&code[..]);

Self {
Expand Down
1 change: 1 addition & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ keywords = ["no_std", "ethereum"]
edition = "2018"

[dependencies]
bytes = { version = "1", default-features = false }
evm-core = { version = "0.33", path = "../core", default-features = false }
primitive-types = { version = "0.10", default-features = false }
sha3 = { version = "0.8", default-features = false }
Expand Down
8 changes: 2 additions & 6 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub use crate::interrupt::{Resolve, ResolveCall, ResolveCreate};

use alloc::rc::Rc;
use alloc::vec::Vec;
use bytes::Bytes;

macro_rules! step {
( $self:expr, $handler:expr, $return:tt $($err:path)?; $($ok:path)? ) => ({
Expand Down Expand Up @@ -84,12 +85,7 @@ pub struct Runtime<'config> {

impl<'config> Runtime<'config> {
/// Create a new runtime with given code and data.
pub fn new(
code: Rc<Vec<u8>>,
data: Rc<Vec<u8>>,
context: Context,
config: &'config Config,
) -> Self {
pub fn new(code: Bytes, data: Rc<Vec<u8>>, context: Context, config: &'config Config) -> Self {
Self {
machine: Machine::new(code, data, config.stack_limit, config.memory_limit),
status: Ok(()),
Expand Down
9 changes: 2 additions & 7 deletions src/executor/stack/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,12 +703,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
self.state.inc_nonce(address);
}

let mut runtime = Runtime::new(
Rc::new(init_code),
Rc::new(Vec::new()),
context,
self.config,
);
let mut runtime = Runtime::new(init_code.into(), Rc::new(Vec::new()), context, self.config);

let reason = self.execute(&mut runtime);
log::debug!(target: "evm", "Create execution using address {}: {:?}", address, reason);
Expand Down Expand Up @@ -905,7 +900,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
};
}

let mut runtime = Runtime::new(Rc::new(code), Rc::new(input), context, self.config);
let mut runtime = Runtime::new(code.into(), Rc::new(input), context, self.config);

let reason = self.execute(&mut runtime);
log::debug!(target: "evm", "Call execution using address {}: {:?}", code_address, reason);
Expand Down