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: avoid tracing when dry-run #238

Merged
merged 1 commit into from
Feb 22, 2024
Merged
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
4 changes: 2 additions & 2 deletions crates/zkwasm/src/loader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl<E: MultiMillerLoop, T, EnvBuilder: HostEnvBuilder<Arg = T>> ZkWasmLoader<E,
) -> Result<TestCircuit<E::Scalar>> {
let (env, wasm_runtime_io) = EnvBuilder::create_env_without_value(envconfig);

let compiled_module = self.compile(&env, true)?;
let compiled_module = self.compile(&env, false)?;

let builder = ZkWasmCircuitBuilder {
tables: Tables {
Expand Down Expand Up @@ -164,7 +164,7 @@ impl<E: MultiMillerLoop, T, EnvBuilder: HostEnvBuilder<Arg = T>> ZkWasmLoader<E,
envconfig: EnvBuilder::HostConfig,
) -> Result<Vec<E::G1Affine>> {
let (env, _) = EnvBuilder::create_env_without_value(envconfig);
let compiled = self.compile(&env, true)?;
let compiled = self.compile(&env, false)?;

let table_with_params = CompilationTableWithParams {
table: &compiled.tables,
Expand Down
100 changes: 55 additions & 45 deletions crates/zkwasm/src/runtime/wasmi_interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,23 +124,18 @@ impl WasmiRuntime {
let instance = ModuleInstance::new(&module, imports, Some(tracer.clone()))
.expect("failed to instantiate wasm module");

let fid_of_entry = {
let idx_of_entry = instance.lookup_function_by_name(tracer.clone(), entry);

tracer
.clone()
.borrow_mut()
.static_jtable_entries
.push(StaticFrameEntry {
enable: true,
frame_id: 0,
next_frame_id: 0,
callee_fid: idx_of_entry,
fid: 0,
iid: 0,
});

if let Some(idx_of_start_function) = module.module().start_section() {
// For performance
if dry_run {
Ok(CompiledImage {
entry: entry.to_owned(),
tables: CompilationTable::default(),
instance,
tracer,
})
} else {
let fid_of_entry = {
let idx_of_entry = instance.lookup_function_by_name(tracer.clone(), entry);

tracer
.clone()
.borrow_mut()
Expand All @@ -149,37 +144,52 @@ impl WasmiRuntime {
enable: true,
frame_id: 0,
next_frame_id: 0,
callee_fid: idx_of_start_function,
fid: idx_of_entry,
callee_fid: idx_of_entry,
fid: 0,
iid: 0,
});
}

if instance.has_start() {
module.module().start_section().unwrap()
} else {
idx_of_entry
}
};
if let Some(idx_of_start_function) = module.module().start_section() {
tracer
.clone()
.borrow_mut()
.static_jtable_entries
.push(StaticFrameEntry {
enable: true,
frame_id: 0,
next_frame_id: 0,
callee_fid: idx_of_start_function,
fid: idx_of_entry,
iid: 0,
});
}

if instance.has_start() {
module.module().start_section().unwrap()
} else {
idx_of_entry
}
};

let itable = tracer.borrow().itable.clone().into();
let imtable = tracer.borrow().imtable.finalized(zkwasm_k());
let elem_table = tracer.borrow().elem_table.clone();
let configure_table = tracer.borrow().configure_table.clone();
let static_jtable = tracer.borrow().static_jtable_entries.clone();

Ok(CompiledImage {
entry: entry.to_owned(),
tables: CompilationTable {
itable,
imtable,
elem_table,
configure_table,
static_jtable,
fid_of_entry,
},
instance,
tracer,
})
let itable = tracer.borrow().itable.clone().into();
let imtable = tracer.borrow().imtable.finalized(zkwasm_k());
let elem_table = tracer.borrow().elem_table.clone();
let configure_table = tracer.borrow().configure_table.clone();
let static_jtable = tracer.borrow().static_jtable_entries.clone();

Ok(CompiledImage {
entry: entry.to_owned(),
tables: CompilationTable {
itable,
imtable,
elem_table,
configure_table,
static_jtable,
fid_of_entry,
},
instance,
tracer,
})
}
}
}
2 changes: 1 addition & 1 deletion third-party/wasmi
Submodule wasmi updated 2 files
+18 −14 src/module.rs
+4 −0 src/tracer/mod.rs
Loading