-
Notifications
You must be signed in to change notification settings - Fork 357
Open
Labels
addition/proposalNew features or enhancementsNew features or enhancementsneeds implementer interestMoving the issue forward requires implementers to express interestMoving the issue forward requires implementers to express interesttopic: api
Description
We have a binary format that we would like to parse with WebAssembly. But the problem is that we have to copy the file's contents to WebAssembly.Memory before doing anything. Which is slow.
So currently the code would look roughly like this:
const response = await fetch("file.bin");
const fileBytes = new Uint8Array(await response.arrayBuffer());
const wasmMemory = new WebAssembly.Memory({
initial: pagesCountRequredForWasmModule(fileBytes.length)
});
const wasmMemoryBytes = new Uint8Array(wasmMemory);
wasmMemoryBytes.set(fileBytes);
const {instance} = await WebAssembly.instantiateStreaming(fetch(wasmUrl), { env: { memory: wasmMemory } });
instance.exports.parse();
But it could be more like:
const response = await fetch("file.bin");
const wasmMemory = new WebAssembly.Memory({
initial: pagesCountRequredForWasmModule(response.headers.get('Content-Length'))
});
await response.preAllocatedArrayBuffer(wasmMemory.buffer, offset);
const {instance} = await WebAssembly.instantiateStreaming(fetch(wasmUrl), { env: { memory: wasmMemory } });
instance.exports.parse();
The same approach would probably help with WebGPU's mapped memory.
Metadata
Metadata
Assignees
Labels
addition/proposalNew features or enhancementsNew features or enhancementsneeds implementer interestMoving the issue forward requires implementers to express interestMoving the issue forward requires implementers to express interesttopic: api