Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

deno: add static ESM export for the webassembly bytes #88

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kunring
Copy link

@kunring kunring commented Aug 7, 2022

Description

Currently the .wasm file is only importable dynamically. This is a problem for multiple reasons. In the spirit of Deno's ecosystem, all imports that can be static should be static. Deno's native bundler won't be able to resolve dynamic imports, but instead leaves them as dynamic. This means that the .wasm has to be loaded from the internet every time the program is ran.

This change doesn't touch the current system, but instead adds an alternative static way to import the .wasm. Usage is as follows:

import { bytes } from "./melody_wasm_static.js"
import { initSync, compiler } from "./melody_wasm.js"
initSync(bytes);
console.log(compiler("1 to 32 of <alphanumeric>;"));

This is compliant with the static imports of the Deno ecosystem and Deno's bundler and compiler are able to resolve this to standalone files that don't require an internet connection to execute:
image

There should probably be a mention of this in the documentation, or this should be the only way to import the wasm in the deno module.

Type of change

  • 馃殌 Feature

@yoav-lavi
Copy link
Owner

Thanks @kunring!

I'm currently on mobile but will look into this, if the initialization is synchronous I'd probably do it either automatically in the module or lazily once.

Would be important to see how this performs as it does the base64 decode on every run (although not sure how expensive it'd be, and definitely would be faster than a download), and it would mean creating new versions would be a bit more involved, but if the alternative is downloading the Wasm module on every run it may be worth it (does Deno not cache these at all?)

@kunring
Copy link
Author

kunring commented Aug 11, 2022

Measured with console.time() the base64 decode takes about 15-20ms on my low end machine.

Deno doesn't seem to cache fetch() calls, while static imports are cached by default, so this would speed up consecutive starts.

@kunring
Copy link
Author

kunring commented Aug 11, 2022

I added a Deno script to generate the .js file from the .wasm file in the folder, so that you can simply run that on your pipeline

@kunring kunring closed this Aug 11, 2022
@kunring kunring reopened this Aug 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants