-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
resource limit exceeded when calling go guest functions compiled by tinygo #5613
Comments
I think tinygo produces a wasi command and not a wasi reactor. This means that I think the following would work by using a separate store for every instantiation but I haven't tested it: use wasmtime::{Engine, Linker, Module, Store};
use wasmtime_wasi::WasiCtxBuilder;
fn main() {
let engine = Engine::default();
let wasi = WasiCtxBuilder::new().build();
let mut store = Store::new(&engine, wasi);
let module = Module::from_file(&engine, "./hello.wasm").unwrap();
let mut linker = Linker::new(&engine);
wasmtime_wasi::add_to_linker(&mut linker, |s| s).unwrap();
linker.module(&mut store, "", &module).unwrap();
let func = linker
.get(&mut store, "", "hello")
.unwrap()
.into_func()
.unwrap()
.typed::<(), ()>(&store)
.unwrap();
loop {
let fresh_wasi = WasiCtxBuilder::new().build();
let mut fresh_store = Store::new(&engine, fresh_wasi);
func.call(&mut fresh_store, ()).unwrap();
}
} |
Is there anything tinygo can do here to make it nicer to play with? |
Wasi has two execution models:
See https://github.com/WebAssembly/WASI/blob/069e3a4aee7ecaa8b52bd3c0ebe4fc055c1b1951/legacy/application-abi.md#current-unstable-abi for a more formal specification. Clang uses |
@bjorn3 👍 Your explanations about the wasi execution model spec is very clear~ However, it seems that we couldn't use another new |
I looked at the source and it seemed like it would for for wasi commands provided that you never use
Yeah |
It's a known issue that command modules (like the one I think you're using here) are easy to leak memory with. Note though that you're not required to execute in a command-like fashion and use Note that Wasmtime has had a lot of effort put into making instantiation fast, and it's expected to be viable for applications to make a new instance per request, for example. I'll also note that there's nothing TinyGo specific here, it's more about the embedder and how the module is run. |
@alexcrichton I changed the code as per your suggestion. This time the program could work normally without memory leak anymore~ use wasmtime::{Engine, Linker, Module, Store};
use wasmtime_wasi::WasiCtxBuilder;
fn main() {
let engine = Engine::default();
let wasi = WasiCtxBuilder::new().build();
let mut store = Store::new(&engine, wasi);
let module = Module::from_file(&engine, "./hello.wasm").unwrap();
let mut linker = Linker::new(&engine);
wasmtime_wasi::add_to_linker(&mut linker, |s| s).unwrap();
let instance = linker.instantiate(&mut store, &module).unwrap();
linker.instance(&mut store, "", instance).unwrap();
let func = instance
.get_typed_func::<(), ()>(&mut store, "hello")
.unwrap();
loop {
func.call(&mut store, ()).unwrap();
}
} |
Ok sounds good. I'm going to close this issue as this leak is probably best tracked by #1913 and I believe everything else is accounted for. Note that in your latest example |
Test Case
I want to make a performance test for Go guest functions, hence export an empty function
hello
:Compile:
tinygo build -o hello.wasm -target wasi
Then I use wasmtime crate to run the function repeatedly:
Expected Results
The program should be continuously running without any error.
Actual Results
Versions and Environment
Wasmtime version or commit: 5.0.0
Operating system: MacOS 13.1
Architecture: M1, MacBook Air 2020
The text was updated successfully, but these errors were encountered: