Hi all, we are going to have a WAMR open TSC meeting. This time we will be focused on the topic of moving WASI to component model:
https://github.com/WebAssembly/WASI/pull/549.
Anyone who is interested in this topic is welcome to join the meeting.
Meeting Bridge info: https://github.com/bytecodealliance/wasm-micro-runtime/wiki/TSC-meeting-notes#wamr-tsc-meeting-2023-08-29-900-am-utc
Sorry for that the meeting time is bad for US timezone, we will make video record. Please be free to forward the invitation.
Thank you for the excellent presentation.
Let me bring several questions here. Sorry if I was missing your explanation
I may not be the best person to answer, but just to provide a few partial answers:
meeting notes and shared materials: https://github.com/bytecodealliance/meetings/blob/main/wamr/2023/wamr-08-29.md
good stuff. I believe my MegaCorp can use wamr in some key situations with wasi/components, so I am really looking forward to this, and to contributing code to wamr as well.
@Ayako Akasaka, @Luke Wagner I would like to share the understanding on performance impacts from my recently study and I may be wrong. We should distinguish two major situations here:
About using WasmGC for two memories case, if I remember it correctly, WasmGC operation is between the wasm stack and gc object, linear memory is not involved. Assuming the GC objects are located a global heap managed by the runtime and handles can be shared by multiple instances, the execution path for passing data will be short. On another hand, component will require malloc and free in the linear memory some times, like when flatten argments is more than the max number (15) or types list/string is used in the function type. If the function body is short execution, then malloc/free could be a big overhead. In such situation, WasmGC is expected to be more efficient.
Single memory based linking is probably not what component model intends to address and actually it is more relavent to the compiler toolchain. But single memory based linking is always important usage in my view, in some situations either per-module isolation or multi-languages is not that critical but performance can be critical in the most time. I am hoping it can be also covered in the CM proposal. A big reason is after WASI is turned to CM, people will start to develop and ship components since their work eventually has dependency on WASI. Given everything is component, it will be great and also important that we can reuse shared components from registry service for doing static linking of Wasm.
Those are great points @Wang Xin. I agree with your description of the two major cases and that both are important to support well in the toolchain when producing components that use WASI. I also think that, while more work may be required to flesh out and polish, we can support both very well, including reuse of shared-everything libraries distributed as core modules in a registry. I also think that good support of both will be important not just for WAMR and embedded use cases, but for plenty of other use cases across the wasm ecosystem as well, ultimately giving developers more choices for how to build their applications.
That is an interesting use case for WasmGC that I hadn't considered, thanks for explaining. My expectation is that the >15-flattened-parameter case will be relatively rare, and that the majority of Wit functions will flatten to a small number of parameters that point into linear memory for any variable-sized (list or string) parameters. Moreover, even in these many-parameter cases, due to strong spatial and temporal locality, I expect the cost of copying parameters between linear memories would be low and amortized by the cost of the overall call. That being said, if we were to find the use of WasmGC to be a measurable win, the design of lifting and lowering in the Component Model allow us to add WasmGC as an additional canonical ABI option (canonopt
in the grammar) in an interoperable, backwards-compatible manner in the future.
The cost for implementing the exact method defined in component model proposal may largely depend on the runtime design technique. For example I am curious whether the wasmtime can quickly copy the list/string data without bearing the burden of refering meta data type for every call.
You're right, it does depend on the implementation technique. In the current implementation, Wasmtime's AOT "fusion" of lifting+lowering adapters avoids any use of type metadata at runtime, by construction: fusion essentially produces a single loop for every list
in the function type that reads from the source linear memory, performs any data-type coercion or validation, and writes directly into the destination linear memory, all guided by the type and the canonopt
s of the lifting and lowering side, which are also statically known at AOT compilation time.
I have some doubts about the two allocations per call constant overhead of poll_oneoff, especially when used frequently for async signaling. I wish it would be able to receive a borrow<list> :wink: and return a bit flag in the common <64 descriptor case.
@Christof Petig I agree; I've also suggested changing that particular interface, and we still can in the Preview 2 timeframe. Dan is already talking about changing wasi-poll in this issue, so maybe comment there with what you'd like to see.
Christof Petig said:
I have some doubts about the two allocations per call constant overhead of poll_oneoff, especially when used frequently for async signaling. I wish it would be able to receive a borrow<list> :wink: and return a bit flag in the common <64 descriptor case.
Oh, I realize I confused im- and export ABIs, for imported functions a list argument is borrowed by default. So the allocation happens only for the result, overriding a one time result for cabi_realloc like in the adapter would be possible but still adds overhead.
@Wang Xin
Thank you for your answer. then let me clarify this part.
Single memory based linking is probably not what component model intends to address and actually it is more relavent to the compiler toolchain. But single memory based linking is always important usage in my view, in some situations either per-module isolation or multi-languages is not that critical but performance can be critical in the most time. I am hoping it can be also covered in the CM proposal.
wasi-libc shared library support is what you are saying as "Single memory based linking". isn't it?
Isn't this within the scope of the Component Model's module-linking specification?
From the previous answer, componentize-py is using the same method, I thought this was the method implicitly, just because it wasn't explicitly stated.
sorry. my question is not clear. Let me revise it later.
Last updated: Nov 22 2024 at 17:03 UTC