-
Notifications
You must be signed in to change notification settings - Fork 2
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
Fix wasm issue with multiple instantiation #4
Conversation
This looks good to me! If I understand correctly, I think there is still a case when this will cause issues though, right? With code like this: let first = processor.process(`\`\`\`svgbob\nn\n\`\`\``);
let second = processor.process(`\`\`\`svgbob\nn\n\`\`\``);
await first;
await second; But I'm fine with dealing with that if we run into that problem. |
That was my original understanding of the issue which is why I started checking the allocator and memory size. However, it seemed it was actually related to there being multiple calls to The 2nd test there could actually just have a single test and it would have still failed (since the first test was the first instantiation), but I added a bunch of process calls just in case the memory issue I thought of actually becomes a problem at some point. The one case where it might be a problem is if we somehow use up 272kb (17 pages of 16kb) of memory, which I think is generally unlikely considering Rust cleans up after itself, so subsequent calls shouldn't be a problem. It's only when rendering some extremely massive SVG (which I don't think is ever likely) |
If the current code, if you call the function and then call |
Not in the current code. const render = await getRenderer() // instatiate wasm
render("\`\`\`svgbob\nn\n\`\`\`") // call wasm export But was changed to const render = await getRenderer() // wait for instatiate wasm to be finished
render("\`\`\`svgbob\nn\n\`\`\`") // call wasm export so multiple calls to await processor.process(`\`\`\`svgbob\nn\n\`\`\``) Are guaranteed to not instantiate the wasm multiple times. I thought it was guaranteed before since I used a local variable to check, but that wasn't enough for some reason (still a bit blurry on this one). Wasm is now instantiated upon import. Once you import the module, it has begun. Calling the export const getRenderer = async () => {
if (hasLoaded) return render;
await Promise.resolve();
return render;
}; We can |
Of course! I misread the usage, my bad. Thanks for clarifying! |
This was all we needed to fix it, it seems!
I've moved all code outside of the function call itself so there's no chance for multiple calls to somehow result in multiple instantiations of the same wasm binary.
The test I added would not pass on the old version.
Closes #3