
InNative: Run WebAssembly Outside the Sandbox at 95% Native Speed - blackhole
https://innative.dev/news/introducing-innative/
======
rkagerer
For those curious why it isn't 100%:

 _The only reason we haven’t already gotten to 99% native speed is because
WebAssembly’s 32-bit integer indexes break LLVM’s vectorization due to pointer
aliasing. Once fixed-width SIMD instructions are added, native WebAssembly
will close the gap entirely, because this vectorization analysis will have
happened before the WebAssembly compilation step._

------
feniv
WebAssembly on desktop and servers is maturing pretty rapidly! There are
several backend interpreters already in Rust and Go (life). The native,
compiled options are even faster, Fastly's Lucet compiler and runtime was one
of the first to implement WASI ([https://wasi.dev/](https://wasi.dev/)):
[https://www.fastly.com/blog/announcing-lucet-fastly-
native-w...](https://www.fastly.com/blog/announcing-lucet-fastly-native-
webassembly-compiler-runtime)

The differentiator for InNative seems to be the ability to bypass the sandbox
altogether as well as additional native interop with the OS. Looks promising!

~~~
forty
I'm wondering what's the point of compiling server side stuff in wasm? Unless
I forgot something, all main server languages are rather portable already,
either because they are interpreted (python, node, jvm...) or can be compiled
to many targets (rust, go...).

~~~
zaarn
You're not confined by the instruction set below. It no longer matters if your
language supports PowerPC, Power8, x86, x86_64, ARMv5 through v8 or even more
exotics. Similar to the Java VM, which definitely showed the advantage of
being more easily portable, it decouples the binary you deploy from the actual
hardware.

Rust and Go have support for many targets but not as many as other compilers
(GCC), a coverage problem that can be fixed by using WASM as intermediate and
porting a WASM Runtime to that architecture.

Something like Innative would also enable desktop applications to be
independent of the OS and architecture. The same binary would run on x86_64
Windows, PowerPC Mac and ARMv8 Linux.

It's basically Java but you don't have to use Java to get all the good parts.

(Disclaimer: I know the main dev of innative and do some WASM work myself)

~~~
AnIdiotOnTheNet
> It no longer matters if your language supports PowerPC, Power8, x86, x86_64,
> ARMv5 through v8 or even more exotics

Yeah, instead it matters which WASM runtimes it supports and which archs those
runtimes support.

But that's ok, we just need one more layer of abstraction to fix the whole
mess.

~~~
zaarn
For innative it matters what LLVM supports and LLVM supports already dictates
the support of many programming languages atleast as a superset (Rust and Go
support a subset of what LLVM supports), I don't see how this is "one more
layer of abstraction will fix the whole mess" when it reuses existing
abstractions.

------
p1necone
[https://www.destroyallsoftware.com/talks/the-birth-and-
death...](https://www.destroyallsoftware.com/talks/the-birth-and-death-of-
javascript)

We're well on our way.

~~~
m_fayer
One of my favorite examples of life imitating art.

------
mises
"Run a fast, sandboxed bytecode outside of the sandbox by compiling it into a
binary" so just a binary. I'm not sure I understand why you would use wasm
here. No one writes wasm; you compile to it (usually from llvm ir). Why
couldn't you just go straight from llvm ir to a binary; skip the wasm? I
suspect I'm missing something here, but it doesn't seem to make sense.

~~~
writepub
Because LLVM IR is CPU-Arch specific. For instance, IR for x86 cannot be used
on ARM CPUs, which is also the reason why Apple's bitcode representation
intended to make apps portable, doesn't cross the iOS (ARM) <\--> MacOs (x64)
boundary, unless ARM ISA emulation is happening in Mac (like in Marzipan?)

~~~
vnorilo
It is not so much that the IR is specific, apart from platform intrinsics. It
is that almost any optimization pass will encode architectural details, like
packing and alignment.

------
ryacko
"We could break the stranglehold of i386 on the software industry and free
developers to experiment with novel CPU architectures without having to worry
about whether our favorite language compiles to it."

WASM is equivalent to early 80s ISAs but with different opcodes. Native WASM
would be most efficient.

~~~
mises
Literally the whole point of WASM is fast, sandboxed code. It's not a
language, it's an LLVM target. So why turn LLVM IR into a native binary? It's
basically the same thing as "native wasm", whatever that would mean. "Native
wasm" is just JITed bytecode. Either that, or you're turning it into a normal
binary, in which case, why even use WASM?

~~~
_nhynes
You get a bit of safety because Wasm programs have statically validated
function calls and operate only within linear memory. If there are no bugs in
the stdlib or the bytecode compiler, then the host is still sandboxed from the
module even without virtual memory.

~~~
lightgreen
No, it’s not possible to statically validate that addresses are within linear
memory. WebAssembly implementations do runtime memory access checks (either
with explicit if checks before some loads and stores or with virtual memory
configuration).

~~~
saagarjha
> it’s not possible to statically validate that addresses are within linear
> memory

It might just be me, but I don't think this is what the parent comment said.

~~~
lightgreen
“Statically validated” AFAIU means there are no runtime checks.

E. g. WASM stack local variables and globals are statically validated.
Compiler can translate loads and stores to locals and globals to simple movs.
There are no additional runtime checks, no overhead. Unlike linear memory.

~~~
saagarjha
As far as I could parse that comment, it's saying that function calls are
statically validated and that memory is linear. Not that all memory accesses
can be statically validated.

~~~
writepub
Given WASM's 32 bit address space, you can effectively validate a programs
memory access statically, with a one time initialization in virtual memory -
for instance if you'd like to restrict all WASM memory to 64MB, you can
allocate/map it to the top of a 4GB virtual address space, effectively giving
it a start address of 4GB-64MB.

Since OS/process virtual memory bound checking is handled by the hardware, the
one time setup above will lock down WASM memory access to within the 64MB,
without software runtime overheads.

This is exactly why WASM memory was picked to be linear (unlike virtual memory
that can have holes in continuity)

------
microcolonel
Alternatively: run native code at least 5% slower than before.

~~~
politician
Before or after turning off Hyper Threading and speculative execution on your
Intel microprocessor?

(The point being that 5% slowdown is a drop in the bucket compared to what
we've already lost due to Intel's chip design problems. AIUI, HT is a 15-20%
slowdown, and SE was another 20% slowdown.)

~~~
imtringued
But now you can in theory run your programs on <strange underused
architecture> that doesn't suffer from those vulnerabilities thanks to the
power of WASM.

~~~
politician
> on <strange underused architecture>

Did the Mill CPU finally get first silicon? ;)

------
liquid153
WASM sounds great and all with it’s sandbox like NaCl. But I have to imagine
over 90% of client and server computers are x86 and ARM and I don’t see those
targets losing any share in the near or long term. Also I don’t see wasm being
used in micro controllers as well.

------
Matheus28
Isn’t it also using 32 bit pointers on 64 bit machines? That should also
improve performance a bit.

It’s a shame that the x32 ABI is almost abandoned nowadays, it has some modest
improvements for applications that don’t need that much memory.

~~~
tree123
why u bully me? ily and ur game diep.io

------
AshleysBrain
Isn't the sandbox a useful feature of WebAssembly? It gives you much better
security guarantees than running untrusted native code on your system.

~~~
TheAceOfHearts
It looks like they provide different levels of sandboxing, so you can tweak
things based on your specific requirements.

