Stream: git-wasmtime

Topic: wasmtime / issue #7724 Global sharable memory/store/engin...


view this post on Zulip Wasmtime GitHub notifications bot (Dec 24 2023 at 08:33):

stevefan1999-personal opened issue #7724:

I'm trying to implement the JS interface to WebAssembly using wasmtime with my own little JS engine project but I came across this

A Memory object represents a single memory instance which can be simultaneously referenced by multiple Instance objects. Each Memory object has the following internal slots:

[[Memory]] : a memory address

[[BufferObject]] : an ArrayBuffer whose Data Block is identified with the above memory address

(https://webassembly.github.io/spec/js-api/#memories)

But if you look closely at https://docs.wasmtime.dev/api/wasmtime/struct.Memory.html#impl-Memory, you can see that the only way to create a Memory is by handing it a Store, but to get a Store you must first create it from an Engine and so I think there is currently no way to implement the required semantics the WebAssembly Spec needed me to do.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 24 2023 at 09:57):

bjorn3 commented on issue #7724:

An Engine is meant to be created once at startup and then used on all threads. (You can still create multiple Engines if you need different settings in different places.) The way to model the JS behavior would be to create a single Store for every thread running javascript. Be aware however that all things that are part of a Store can't get deallocated without deallocating the entire Store. As such you can easily run out of memory if you keep a Store around for the entire JS execution.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 02 2024 at 15:32):

alexcrichton closed issue #7724:

I'm trying to implement the JS interface to WebAssembly using wasmtime with my own little JS engine project but I came across this

A Memory object represents a single memory instance which can be simultaneously referenced by multiple Instance objects. Each Memory object has the following internal slots:

[[Memory]] : a memory address

[[BufferObject]] : an ArrayBuffer whose Data Block is identified with the above memory address

(https://webassembly.github.io/spec/js-api/#memories)

But if you look closely at https://docs.wasmtime.dev/api/wasmtime/struct.Memory.html#impl-Memory, you can see that the only way to create a Memory is by handing it a Store, but to get a Store you must first create it from an Engine and so I think there is currently no way to implement the required semantics the WebAssembly Spec needed me to do.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 02 2024 at 15:32):

alexcrichton commented on issue #7724:

I don't have much more to add over what @bjorn3 already mentioned (thanks!) other than the Rust API for wasmtime is intentionally different from the JS API to better suit Rust idioms and cater to Wasmtime's use cases.

Otherwise though given that a Store-per-JS-thread should suffice I'm otherwise going to close this. Let us know though if you've got other questions!


Last updated: Nov 22 2024 at 17:03 UTC