or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
Proposal for Component Pre-initialization
TL;DR
I'm proposing a pre-init method for WebAssembly components which operates on an input component of a certain shape (single memory; no subcomponents), adding temporary export functions to expose the memory and global variables, from which we can create a snapshot using any component-capable Wasm runtime.
Background
One of the major challenges we've faced in designing and implementing shared-everything linking for the component model is that, as of this writing, there are no tools supporting Wizer-style pre-initialization for components. We've discussed various options, including adding such support to either Wizer or Wasmtime, but none of them are particularly attractive. Adding it to Wizer would require adding new APIs to Wasmtime for walking a component instance hierarchy and extracting internal state, and it's not clear that the feature belongs in Wasmtime itself.
Proposal
I'm proposing that we create a new tool, initially focused on the specific shape of component produced by a shared-everything linking operation (single memory; single table; each module instantiated exactly once; no subcomponents), which does the following:
get-{module}-{name}: func() -> {type}
, where{module}
identifies the module,{name}
identifies the global, and{type}
is the lifted type of the global.get-memory: func() -> list<u8>
which returns the entire content of the memory.start
functions from all modules, replacing them with new data segments comprised of the non-zero parts of the memory snapshot captured above. Finally, it will update the initializers for each mutable global to match the snapshot values.Note that, while this proposal only considers a certain shape of component, I expect this technique could be generalized to support arbitrary component graphs. One complication in the general case is that a given module may be instantiated more than once. In that case it may be necessary to edit that module so that it exports its memory and all its mutable globals, and these would be initialized by separate, synthesized modules – one per instantiation.
Also note that, since there's nothing runtime-specific about this approach, we could theoretically use a Wasm interpreter which itself compiles to Wasm and package the whole tool as a Wasm module or component.
Implementation
The
componentize-py
repository contains first draft implementation which I hope will form the basis for a more polished, general-purpose library.