News for hackers. Stuff that matters.
Re:WasmEdge by laurencerowe on Tuesday November 29, 2022 @03:57PM (#33793181)
Interesting to see that it has JavaScript support built in. It seems to be based on QuickJS which will work for some things but as they acknowledge quite slow.

> In the end, running v8 in a cloud-native environment often requires a full stack of software tools consisting of "Linux container + guest OS + node or deno + v8", which makes it much heavier and slower than a simple WasmEdge + QuickJS container runtime.

https://wasmedge.org/book/en/write_wasm/js.html#a-note-on-v8

Whether it's faster or not really depends on the complexity of what's being run. After reading about wasmtime 1.0's super fast 5 microsecond snapshot restore time (https://bytecodealliance.org/articles/wasmtime-1-0-fast-safe...) I did some experiments with QuickJS and Javy which runs QuickJS in wasmtime. Rendering a moderately complex web page with React renderToString production 30kB of html on my MacBook Air M1 took:

- Deno first iteration: 12-20ms

- Deno subsequent iterations: 2-4ms

- qjs native: 18-24ms

- javy (qjs wasmtime): 40-60ms

I've not tried WasmEdge but it's JS performance would presumably fall somewhere between that of qjs native and under wasmtime.

Firecracker claims a ~3ms snapshot restore time on ARM so might be the best way to go currently for such workloads but there is certainly a large subset of problems for which the current performance is adequate.

There has been talk of AOT compilation for SpiderMonkey.wasm (https://bytecodealliance.org/articles/making-javascript-run-...) which I hope this will some day happen since it should close the gap substantially. I recently asked on the ByteCode Alliance Zulip but there hasn't yet been any progress and it requires a substantial amount of work.

Re:WasmEdge by azakai on Tuesday November 29, 2022 @04:05PM (#33793289)
Another thing that would be interesting to measure here is memory usage. QuickJS might be slower (as a minimal interpreter) but at least it should be much smaller than a full optimizing JS engine (running normally or compiled to wasm), both in terms of code size and runtime memory usage. That might matter in some cases.
Re:WasmEdge by hutzlibu on Tuesday November 29, 2022 @04:39PM (#33793702)
"at least it should be much smaller than a full optimizing JS engine, both in terms of code size and runtime memory usage"

Why should QuickJS use less runtime memory?

Genuine question, I just recently learned of QuickJS and what I understand, it is way smaller in itself, meaning you do not need so much memory for the engine itself, but that does not say anything how efficient it is with executing js code. Or are there benchmarks that say, it is also more memory efficient with executing js?

Either way, yes, I also think meassuring memory is important.

Re:WasmEdge by azakai on Tuesday November 29, 2022 @05:05PM (#33794033)
Optimizing VMs often use lots of memory for various reasons. Specific costs in modern optimizing VMs include the memory for the JITed code, and with multiple tiers you end up JITing each function more than once. You also need memory to save information about which functions to tier up (a call count or something more refined). Even things like polymorphic inline caches have a cost, the space for each of those PICs, and the code around them.

A simple interpreter can avoid all those. It can build a very simple and compact bytecode and just execute that.

(But, of course, the speedups in optimizing JITs are usually worth it! 10x or more.)

Re:WasmEdge by galangalalgol on Tuesday November 29, 2022 @07:10PM (#33795190)
Does the engine store compiled binaries for the next time the page is loaded?
Re:WasmEdge by azakai on Tuesday November 29, 2022 @07:16PM (#33795239)
Some (most?) do, yes, here is a V8 article on that for example: https://v8.dev/blog/wasm-code-caching
Re:WasmEdge by galangalalgol on Tuesday November 29, 2022 @07:49PM (#33795474)
That seems to imply julia for wasm on chrome wouldn't have the "time to first plot" issue.
Re:WasmEdge by cmrdporcupine on Tuesday November 29, 2022 @04:09PM (#33793350)
I remain mystified about the value of running JS inside a wasm VM. I see why people want to go there, because they want one tool to rule them all, but I don't get the actual value add. WASM hasn't been built for this. Not yet. You'll be running the garbage collector, compiler, bytecode interpreter fully in an emulated environment. There's bound to be overhead. For no reason. (And remember overhead isn't just slow processing of customer jobs -- it's energy consumption as well.)

There are already multiple runtimes that can run both WebAssembly and Javascript/TypeScript. The JS runtimes themselves. V8 does a great job of running both wasm and JS. And a custom V8 (or JavaScriptCore or whatever) embedding with appropriate sandboxing can be put together without a huge amount of work.

Seems like the better peg for the hole in question if people want support for JS and WASM in a hosted environment.

Re:WasmEdge by juntao on Tuesday November 29, 2022 @04:39PM (#33793700)
Disclaimer: I am a maintainer at WasmEdge.

One of the benefits of running JS in Wasm (specifically the QuickJS approach) is that you can create JS APIs in Rust. That allows you to move a lot of compute intensive operations into Rust while still giving your developers a clean and nice JS API. WasmEdge does this with its JS Tensorflow API:

https://wasmedge.org/book/en/write_wasm/js/tensorflow.html

In fact, we are using Rust to support the entire Node.JS API in WasmEdge. :)

Re:WasmEdge by cmrdporcupine on Tuesday November 29, 2022 @04:47PM (#33793807)
Not to denigrate your work, it's good what you're working on... but I can create JS APIs in Rust with native V8 bindings, too: https://github.com/denoland/rusty_v8/blob/main/examples/proc...

After working on a couple codebases that used wasmtime and wasmer heavily, I think if I were to start from scratch I'd just use V8 as my WASM runtime.

(And the model I would follow would be to containerize the V8 runtime piece inside its own cgroup, with resource budgets and permission constraints. cgroups accounting beats the limited and inefficient accounting one gets from the various WASM runtime opcode based accounting systems.)

Re:WasmEdge by juntao on Tuesday November 29, 2022 @07:08PM (#33795161)
Personally, I believe v8 is and always will be primarily focused on the browser use case. It’s support for wasi, container tooling will always take a back seat compared with priorities in the browser.

Today, there are a large set of Rust apps that can run in WasmEdge, wasmtime, Fermyon spin, wasmCloud etc, but would not run on v8’s embedded Wasm engine …

However, I do agree that v8 excels in JavaScript.

Re:WasmEdge by azakai on Tuesday November 29, 2022 @07:25PM (#33795303)
The design of WASI and the component model are layered, though: you could start with V8 and build a runtime with full WASI etc. support.

In fact, Node.js and Deno have both done exactly that, a V8 core with layered APIs on top including WASI.

Re:WasmEdge by laurencerowe on Tuesday November 29, 2022 @04:52PM (#33793872)
My interest comes from wanting to see more performant options for per-request isolation in JavaScript applications. There have been bugs on popular web services returning information for the wrong user caused by inadvertently using global or module level variables.

Isolates are one option but I believe startup time for isolates with a snapshot is actually slower than Firecracker's snapshot restore.

Developing with Firecracker is somewhat annoying since it requires support for nested virtualization (doesn't work on Mac M1 or AWS, though does on GCP and GitHub Codespaces. The M2 has hardware support so development on Mac should work eventually.)

The various WebAssembly runtimes have really put a lot of work into getting fast snapshot restore with Wasmtime 1.0 doing so in microseconds. I'd love to be able to run server rendering in such an environment.

Re:WasmEdge by mike_hearn on Wednesday November 30, 2022 @05:01AM (#33798850)
You could take a look at GraalJS. It supports its own form of isolates and they can be created very fast, because an isolate setup is basically mmapping the pre-calculated heap into another area of memory and starting up another thread. I never measured it but it shouldn't be particularly slow. It also means you can mix languages.
Re:WasmEdge by intelVISA on Tuesday November 29, 2022 @05:32PM (#33794313)
Interesting gamble to build a whole company on top of what is effectively a wrapper for Bellard's work (qjs), wonder how it'll play out.
Re:WasmEdge by rdtsc on Tuesday November 29, 2022 @09:08PM (#33796058)
Not OP but I was considering using it as well. I could see it going either way. If Fabrice stays interested in the project and keeps improving it, it could be a great win. If he moves on to other things, perhaps not.

I've been looking at quickjs issues and forks and see a lot of random fixes from various people and most of them don't seem to be accepted or responded to:

* https://github.com/bellard/quickjs/issues/131 * https://github.com/bellard/quickjs/issues/130 * https://github.com/bellard/quickjs/issues/129 * https://github.com/bellard/quickjs/issues/123 * https://github.com/bellard/quickjs/issues/111 * https://github.com/bellard/quickjs/issues/103 * https://github.com/bellard/quickjs/issues/96

The mailing list doesn't seem to have a lot of responses either. So, it's actually hard to say. The first instinct is it's great to base a product on such a talented programmer's work, but it seems you should be proficient enough to debug and fix issues yourself to do that.

No blame or slight to Fabrice, of course, I am always impressed by his work, and he certainly doesn't owe anyone any of his time.

Re:WasmEdge by syrusakbary on Tuesday November 29, 2022 @07:38PM (#33795388)
Interesting. Have you tried to benchmark it also with Wasmer [1]? I'm quite curious of the results!

[1] https://wasmer.io/

Re:WasmEdge by jeffparsons on Tuesday November 29, 2022 @10:59PM (#33796870)
I'm impressed — I don't think I've ever seen you miss an opportunity to promote your company. I assume you have some kind of keyword alert set up? Kudos on the mad hustle!
Re:WasmEdge by kumarski on Wednesday November 30, 2022 @12:38AM (#33797377)
Syrus is a technocrat's technocrat and a big open source contributor. I watch from the sidelines in awe as the community builds wasmer and the wasm ecosystem.
Re:WasmEdge by laurencerowe on Wednesday November 30, 2022 @02:50AM (#33798079)
How is snapshot restore performance in wasmer?
Re:WasmEdge by syrusakbary on Wednesday November 30, 2022 @03:00AM (#33798138)
I guess you are referring to wizer [1]? (it's the closest to snapshot restore in the WebAssembly world). In case you are referring to that, the wizer strategy is valid for any Wasm runtime (and it will be fast once the Wasm module is snapshotted by wizer).

If you refer towards Wasm module loading times (once a module is already been precompiled), Wasmer is already one of the fastest ones.

https://github.com/bytecodealliance/wizer