10 ms·
InNative: Run WebAssembly Outside the Sandbox at 95% Native Speed
- ryacko 7y ago"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 7y agoLiterally 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?
- bane 7y agohttps://en.wikipedia.org/wiki/Java_processor https://en.wikipedia.org/wiki/Java_processor
- ryacko 7y agox86 is translated to micro-ops in the processor. Why use x86 if you don't need a half-carry flag?
- _nhynes 7y agoYou 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 7y agoNo, 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 7y ago> 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 7y ago“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 7y agoAs 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.
- lightgreen 7y agoFair point, author indeed said that function calls are statically validated, but did not say linear memory access is statically validated. This phrase “host is still sandboxed from the module even without virtual memory” confused me. Because technically any interpreter (even qemu) can run without virtual memory with more or less expensive runtime checks.
- writepub 7y agoGiven 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)
- hackerpacker 7y ago" It's not a language" It sure looks like a language to me, like some sort of assembly language. https://webassembly.org/getting-started/advanced-tools/ https://webassembly.org/getting-started/advanced-tools/ https://developer.mozilla.org/en-US/docs/WebAssembly/Text_format_to_wasm https://developer.mozilla.org/en-US/docs/WebAssembly/Text_fo... granted this is a textual representation (very useful in certain circumstances) but that is semantics. Having done plenty of assembly, I don't see a huge distinction here.
- WAHa_06x36 7y agoLLVM IR is not architecture-independent. It encodes architecture and ABI assumptions, and is not portable. Also, this is not "JITed bytecode", it is compiled AOT.
- pjmlp 7y agoThe PNaCL and Apple's variants are architecture independent.
- WAHa_06x36 7y agoWell. They pick an architecture and stick with it, more like. But one is dead in favour of WebAssembly and the other is an internal format.
- pjmlp 7y agoIt doesn't change the fact that they do exist. PNaCL died in favour of WebAssembly due to politics. With Chrome today's might, the decision would most likely be a different one.
- FullyFunctional 7y agoI used to resort to binary translation for experimental CPU projects, but WASM looks like a much better starting point. The controversial lack of arbitrary control flow is a massive advantage for me. Writing an complete compiler backend/asm/ld is a significant undertaking which is only worthwhile for very stable architectures.
- nullwasamistake 7y agoJava Bytecode is similar to WASM, opcode wise. Bytecode purposely omits many instructions that can be done with equivalents to fit the whole ISA in single byte instructions. WASM is similar for the same reason, code density. The main difference in Bytecode/WASM is memory model and branching support. But you could say that both are equivalent to 80's ISA's. Precompiled Java is closer to WASM than many would like to admit, so I expect performance to be similar in the long run. This isn't so bad, Java reaches over half native speed on many benchmarks. It's amazing that we'll be able to run untrusted code so quickly
- scriptproof 7y agoYou can avoid the effort to use the uppercase key and write wasm (or Wasm), that is the correct typography. Asm in wasm is acronym for nothing.
- mises 7y agoAsm for Assembly, so maybe WAsm is correct?
- imtringued 7y agoNot it wouldn't be because most bytecodes generally operate at a higher level. A single java call instruction can in theory turn into an unbounded number of machine instructions through inlining. Therefore limiting the machine to only executing entire java instructions will make it extremely slow because it cannot use any optimizations.
- mises 7y ago"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.
- chr1 7y agoThat way the same binary could run on machines with different architectures. There is also work in progress to define common system api for wasm, which would allow to run the same binary on any platform.
- jmisavage 7y agoFor any other reader, the common system API that chr1 speaks of is called WASI. Mozilla's announcement of it is here: https://hacks.mozilla.org/2019/03/standardizing-wasi-a-webassembly-system-interface/ https://hacks.mozilla.org/2019/03/standardizing-wasi-a-webas...
- techntoke 7y agoBecause WASM is already bad for user security, they want to make it worse.
- feniv 7y agoWebAssembly 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-webassembly-compiler-runtime https://www.fastly.com/blog/announcing-lucet-fastly-native-w... 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 7y agoI'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...).
- aclatuts 7y agoIt is nice in development to have bcrypt, openssl, etc for other languages without a build step and build tools
- zaarn 7y agoYou'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)
- 7y ago
- p1necone 7y agohttps://www.destroyallsoftware.com/talks/the-birth-and-death-of-javascript https://www.destroyallsoftware.com/talks/the-birth-and-death... We're well on our way.
- m_fayer 7y agoOne of my favorite examples of life imitating art.
- microcolonel 7y agoAlternatively: run native code at least 5% slower than before.
- politician 7y agoBefore 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 7y agoBut 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 7y ago> on <strange underused architecture> Did the Mill CPU finally get first silicon? ;)
- ziftface 7y agoLike the article said, in practice the WebAssembly can actually be faster, because it can use all the optimizations for the target machine.
- Matheus28 7y agoIsn’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 7y agowhy u bully me? ily and ur game diep.io
- rkagerer 7y agoFor 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.
- AshleysBrain 7y agoIsn't the sandbox a useful feature of WebAssembly? It gives you much better security guarantees than running untrusted native code on your system.
- TheAceOfHearts 7y agoIt looks like they provide different levels of sandboxing, so you can tweak things based on your specific requirements.
- liquid153 7y agoWASM 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.
- jamewatson 7y agoI think this is a knock on Google; I thought the old version was actually a new, better version ... the old one way runs faster.