Stream: general

Topic: Fast AOT-compiled JS


view this post on Zulip Laurence Rowe (Sep 07 2022 at 23:54):

Hello,

Is there anywhere I could read more about the AOT JavaScript compilation mentioned in this article from last year: https://bytecodealliance.org/articles/making-javascript-run-fast-on-webassembly

In combination with the fast instantiation coming in Wasmtime 1.0 it would seem quite compelling.

Thanks!

JavaScript in the browser runs many times faster than it did two decades ago. And that happened because the browser vendors spent that time working on intensive performance optimizations.

view this post on Zulip Joel Dice (Sep 08 2022 at 13:27):

When I spoke with @Saúl Cabrera about this a few weeks ago, he estimated that about 1000 hours of work are needed to make SpiderMonkey AOT usable. I'm not sure if anyone has actually been working on it lately, though.

In the meantime, we've been seeing good FaaS performance with the combination of QuickJS + Wizer + Wasmtime that Javy uses. It won't give you the same kind of throughput for CPU-heavy workloads as AOT compilation, but it's great for fast instantiation and I/O-bound workloads.

JS to WebAssembly toolchain. Contribute to Shopify/javy development by creating an account on GitHub.

view this post on Zulip Laurence Rowe (Sep 08 2022 at 23:40):

Many thanks for pointing me to Javy.

I experimented with using React renderToString on a moderately complex page from a real app (30KB html rendered.) Timings are just for the renderToString on my MacBook Air M1.

Deno first iteration: 12-20ms
Deno subsequent iterations: 2-4ms
qjs: 18-24ms
javy: 40-60ms

AOT would make a substantial difference but his definitely opens up a lot of possibilities.

I guess running something like Deno in Firecracker is probably faster for this use case for now (they claim a 3-7ms snapshot restore time) but it's more tricky to develop since there's no nested virtualization on M1 Macs or EC2 (though it does work on GCP and Github Codespaces.)

view this post on Zulip Cwasi4wasm (Nov 16 2022 at 14:57):

Anyone compiling quickjs from shopify? I forked the toolchain on javy and enabled file imports. I'm now at a point where im trying to support nodejs apis to make them run in wasm/wasi but it seems like a really daunting task because of the number of libraries. Has anyone encountered this and how did they go about it if you don't mind me asking

view this post on Zulip Joel Dice (Nov 16 2022 at 17:24):

We're using Javy's quickjs-wasm-rs crate in our experimental Spin JS SDK project. So far, we've only implemented a couple of NodeJS APIs, namely fs.readFile and fs.readdir which primarily defer to Rust code for the implementations. The Rust code also populates process.env with any variables in the WASI environment.

Contribute to fermyon/spin-js-sdk development by creating an account on GitHub.
Contribute to fermyon/spin-js-sdk development by creating an account on GitHub.
Contribute to fermyon/spin-js-sdk development by creating an account on GitHub.
Contribute to fermyon/spin-js-sdk development by creating an account on GitHub.

view this post on Zulip Joel Dice (Nov 16 2022 at 17:26):

We also provide a minimal fetch API, Math.random(), etc.

view this post on Zulip Joel Dice (Nov 16 2022 at 17:28):

Not sure what your end goal is, but I would recommend adding host APIs (e.g. NodeJS-style or Web API) as you encounter the need for them (e.g. libraries that depend on them) rather than try to tackle them all at once.


Last updated: Nov 22 2024 at 16:03 UTC