Live data from Hacker News

Ask HN: What are the use cases of WASM outside the browser?

news.ycombinator.com

21–27 of 27 posts

Re: Ask HN: What are the use cases of WASM outside the browser?

#21
post #8

An OS built on top of WASM can provide modern features without the bloat of current CPUs, e.g. MMUs.

Not if you care about side channels. There really aren't any good solutions here that let you safely run untrusted code in a shared address space. Yes, you can slap barriers behind every single branch and after every single store (memory ordering violations can cause mispeculations in straight line code!), but that's going to come with an enormous performance cost (academics regularly brag about inventing new mitigations with ""only"" a 20% performance overhead lmao). The only option we've really found is to make interesting secrets inaccessible (site isolation in Chrome, for example). Trying to shove all user applications into a flat address space would mean giving any application the ability to read arbitrary memory, which is not great.

Re: Ask HN: What are the use cases of WASM outside the browser?

#22
I think a big use case is running kernels/UDFs directly inside databases or data infrastructure systems. For example, [0]. Imagine you need a custom function in postgres, but instead of implementing it in C and shipping a shared library, you would implement it in WASM.

[0] https://redpanda.com/blog/wasm-architecture

Re: Ask HN: What are the use cases of WASM outside the browser?

#23
post #8

An OS built on top of WASM can provide modern features without the bloat of current CPUs, e.g. MMUs.

WASM sandboxing requires an MMU. It achieves its performance by trapping OOB reads via page faults.

I think they just worded that poorly. I suspect their suggestion is not that you run with the MMU _off_ (as doing so would trash your perf anyways since everything becomes uncacheable!) but rather that you don't need to context switch the page tables, which can lead to some pretty decent performance gains given that you can (on some platforms) avoid TLB flushes. Nowadays though I seriously would not consider the page table switch to be a significant cost since (in ARMv8 anyways) you have ASIDs and so switching tables is just a single msr+isb.

Re: Ask HN: What are the use cases of WASM outside the browser?

#24
post #2

Maybe a runtime for application plugins? You expose some apis in the wasm runtime and plug-in developers only have to target the wasm runtime.

Kong gateway wrote an article about a wasm framework for nginx: https://konghq.com/blog/around-v8-in-seventy-days-bringing-a...

Re: Ask HN: What are the use cases of WASM outside the browser?

#25
post #21
post #8

An OS built on top of WASM can provide modern features without the bloat of current CPUs, e.g. MMUs.

Not if you care about side channels. There really aren't any good solutions here that let you safely run untrusted code in a shared address space. Yes, you can slap barriers behind every single branch and after every single store (memory ordering violations can cause mispeculations in straight line code!), but that's going to come with an enormous performance cost (academics regularly brag about inventing new mitigat…

The solution to fixing side channels is no raw multithreading or shared memory. Solutions like Nix are better for parallel computation.

Re: Ask HN: What are the use cases of WASM outside the browser?

#26
post #23

Earlier quoted context omitted.

WASM sandboxing requires an MMU. It achieves its performance by trapping OOB reads via page faults.

I think they just worded that poorly. I suspect their suggestion is not that you run with the MMU _off_ (as doing so would trash your perf anyways since everything becomes uncacheable!) but rather that you don't need to context switch the page tables, which can lead to some pretty decent performance gains given that you can (on some platforms) avoid TLB flushes. Nowadays though I seriously would not consider the page…

Nope, I meant what I wrote. You don't need an MMU, because you have no need for virtual memory or similar. Checking an integer is within some bounds is a much simpler problem, and in some cases the check can be elided through analysis on the code.

Re: Ask HN: What are the use cases of WASM outside the browser?

#27
post #26
post #23

Earlier quoted context omitted.

I think they just worded that poorly. I suspect their suggestion is not that you run with the MMU _off_ (as doing so would trash your perf anyways since everything becomes uncacheable!) but rather that you don't need to context switch the page tables, which can lead to some pretty decent performance gains given that you can (on some platforms) avoid TLB flushes. Nowadays though I seriously would not consider the page…

Nope, I meant what I wrote. You don't need an MMU, because you have no need for virtual memory or similar. Checking an integer is within some bounds is a much simpler problem, and in some cases the check can be elided through analysis on the code.

unfortunately, then, you'll need new CPUs. You don't _need_ memory protection but CPUs today are built on the assumption that you are using it and have thus stapled many critical attributes about memory to it (such as cacheability and shareability).
Post reply on HN