From 02254a6b3846d320350707965469d86c762dad54 Mon Sep 17 00:00:00 2001 From: Zhang Junyu Date: Tue, 20 Feb 2024 08:19:01 +0800 Subject: [PATCH] perf: avoid tracing when dry-run --- crates/zkwasm/src/loader/mod.rs | 4 +- .../zkwasm/src/runtime/wasmi_interpreter.rs | 100 ++++++++++-------- third-party/wasmi | 2 +- 3 files changed, 58 insertions(+), 48 deletions(-) diff --git a/crates/zkwasm/src/loader/mod.rs b/crates/zkwasm/src/loader/mod.rs index 953a9a089..91cc46c4a 100644 --- a/crates/zkwasm/src/loader/mod.rs +++ b/crates/zkwasm/src/loader/mod.rs @@ -107,7 +107,7 @@ impl> ZkWasmLoader Result> { 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 { @@ -164,7 +164,7 @@ impl> ZkWasmLoader Result> { 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, diff --git a/crates/zkwasm/src/runtime/wasmi_interpreter.rs b/crates/zkwasm/src/runtime/wasmi_interpreter.rs index edb6d01aa..1f9a2ecee 100644 --- a/crates/zkwasm/src/runtime/wasmi_interpreter.rs +++ b/crates/zkwasm/src/runtime/wasmi_interpreter.rs @@ -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() @@ -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, + }) + } } } diff --git a/third-party/wasmi b/third-party/wasmi index c888d0bc1..e508d7cf5 160000 --- a/third-party/wasmi +++ b/third-party/wasmi @@ -1 +1 @@ -Subproject commit c888d0bc152fa8ee4d5f7d0d7746ddf18cddb8c1 +Subproject commit e508d7cf5b06a5a9a94bc5d7c9e27e5cdccd0f4c