Created
January 15, 2025 20:29
-
-
Save alexcrichton/6815a5d57a3c5ca94a8d816a9fcc91af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use wasmtime::{Module, Store}; | |
fn main() { | |
let _ = env_logger::try_init(); | |
for i in 0.. { | |
if i % 1000 == 0 { | |
println!("{i}"); | |
} | |
let mut config = wasmtime::Config::new(); | |
config.parallel_compilation(false); | |
unsafe { | |
config.cranelift_flag_set("wasmtime_linkopt_padding_between_functions", "53199"); | |
} | |
let engine = wasmtime::Engine::new(&config).unwrap(); | |
let store = Store::new(&engine, ()); | |
std::thread::scope(|s| { | |
let t1 = s.spawn({ | |
let store = Store::new(store.engine(), store.data().clone()); | |
move || { | |
Module::new(store.engine(), r#"(module (func (export "run")))"#).unwrap(); | |
} | |
}); | |
let t2 = s.spawn({ | |
let mut store = Store::new(store.engine(), store.data().clone()); | |
move || { | |
let module = | |
Module::new(store.engine(), r#"(module (func (export "run")))"#).unwrap(); | |
let instance = wasmtime::Instance::new(&mut store, &module, &[]).unwrap(); | |
let func = instance.get_func(&mut store, "run").unwrap(); | |
func.call(&mut store, &[], &mut []).unwrap(); | |
} | |
}); | |
t1.join().unwrap(); | |
t2.join().unwrap(); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment