5 ms·
How does this all compare to the old and dead idea that you'd just run java applets from your browser? Is it believed that browsers are harder targets than JVMs
by jeffbee 5y ago
How does this all compare to the old and dead idea that you'd just run java applets from your browser? Is it believed that browsers are harder targets than JVMs?
- Sammi 5y agoSteve Klabnik had a really great blog post about this: https://steveklabnik.com/writing/webassembly-is-more-than-just-the-web https://steveklabnik.com/writing/webassembly-is-more-than-ju... Basically webassembly is the same core idea as jvm, but redone with all the lessons from the last three decades. A modern cross platform runtime for anything anywhere.
- AnIdiotOnTheNet 5y agoHaving read the spec and partially implemented my own WASM VM, if it's goal was to be universal then it wasn't designed very well IMO. Off the top of my head, it presumes that only 32 and 64 bit types exist, that everything is little-endian, and has parametric instructions[0] for some reason. Pretty sure WASM was designed only for web browsers with any seriousness and any other usecases are just enthusiastic people trying to shoehorn it into other places because you can technically do it and it's the new exciting hotness. [0] from memory I think it is only DROP, which makes the decision even more maddeningly silly.
- fizx 5y agoAll of the old Java (and ActiveX, ewww) was operating under the principle that you'd grant the applet more permissions than javascript, whereas WASM grants the same or fewer permissions!
- jeffbee 5y agoBut for a program like ImageMagic or 7Zip to have any utility, it must be reading and writing files somewhere. I'm just trying to figure out why I would download and run a wasm program to handle these tasks. Why would I trust it?
- fizx 5y agoIt could be reading and writing to a virtual filesystem in your browser. You could then view the transformed file inside the browser as well.
- cxr 5y agoThe HTML5 standard has included the ability to read files for longer than ECMA-262 has had modules and classes (which has already been quite some time—those appeared in ES2015). Writing files is a different matter, but you can easily prompt the user with the browser-native download manager when your app has finished processing the input and the user indicates they want to save. This, too, has been available for a long time. The Chrome team has introduced a new, experimental file access API, but it's not strictly necessary for any of this and probably gives up too much power[1]. Before that, there were the DOM Load and Save APIs (2002)[2], which never got implemented. The future would look less grim if they chose instead to do something like reboot Google Gears, providing a supplemental component that implemented e.g. the remoteStorage protocol that just happened to use your local disk for its backing store—but in a way that's completely transparent to the web app, which shouldn't even be concerned with things like that. It would also translate much better for mobile devices, too, which may or may not have any notion of a desktop-like file system exposed to the user. 1. https://news.ycombinator.com/item?id=30766276 https://news.ycombinator.com/item?id=30766276 2. http://www.w3.org/TR/DOM-Level-3-ASLS http://www.w3.org/TR/DOM-Level-3-ASLS
- tyingq 5y agoWell, partially because browser javascript has more permissions and features now than it used to.
- colordrops 5y agoDifferences: Webassembly uses the same bytecode and runs on the same VM as javascript, making it much more stable and reliable than the embedded JVM was. It is already in every browser and doesn't need to be installed separately, and has a faster startup time. It can write to the same canvases as JS so it doesn't have to be a separate visual space. Also an obvious difference is that you can use a lot more languages to target webassembly.
- jerf 5y ago"has a faster startup time" Just as an idle muse, I wonder if that's true. Java's startup time on a 133MHz Pentium running on spinning rust is one thing, JS starting up on a multicore multigigahertz monster backed by an SSH is quite another. I wonder if the WASM startup really is any faster than Java in some absolute sense? Kinda like how "Go has a fast compiler" if you compare it to modern compilers on modern workloads, but is beaten handily by Turbo Pascal... as long as you don't mind that the output of the Turbo Pascal compiler is a wee bit out of date.
- colordrops 5y agoYes because it's already started when you load a page.
- jollybean 5y agoI disagree wit this. WASM does not run on the same VM as javascript, or rather, that V8 happens to provide the facility for both, does not mean that much. They are effectively separate things. Now, if you mean to say there's some degree of interop via a chunk of memory between the two, then fine, but that's not particularly an advantage. WASM is a bit different between browsers, it's not 'stable'. That said, Applet/JVM are 'nowhere' these days and would require specific installation. WASM is not 'faster to start' and it's not even 'fast' <-- this, and lack of clean interop is the worst thing about WASM. It's slow! If you combined the fact you have to go across an ugly 'bridge' between JS and WASM to do almost anything, it's probably not worth it for performance gains, and certainly comes with major dev. cost. 'Targeting more languages'? Really? Java, Swift, Python, Go - not really. You can target C++/C and Rust but only in very specific ways. So the advantage for WASM would be 1) security for user, but in reality v8/JS is already secure 2) performance, but in most cases it's not true 3) 'hide your code' yes, this is nice for some algs. and 4) port your C++ algs to the browser like Photoshop/Autocad. So far the reality is that it just doesn't fully add up. Maybe some day.
- kannanvijayan 5y agoFrom 10,000 feet, the overall setup looks roughly the same. As in many situations, though, the devil is in the details. There are a few key distinctions to make between the JVM approach and WASM's approach. The first is that the JVM was a very high-level VM. It exposed a high-level typed bytecode with support for complex structured types, a sophisticated garbage collected heap model, and out-of-the-box system APIs with a huge surface area. The second is related, in that the JVM's security model was very much mixed up with its type-safety guarantees. This lead to significant complexity in the implementation of its security model. There are places in the JVM spec where you literally have to walk up the java virtual stack, looking at security tokens along the way, to determine if a particular system call should pass through or not. All of this stemmed from a design perspective that very much derived from our ideas of best practices at the time. The third is that the Java spec very much relied on load-time verification of strong interfaces across modules. This is one of the reasons for Java applets' famously poor startup times. When a single class-file was loaded, all of its dependencies must be loaded and its consumed interfaces type-checked, and this prompts type-validation of _those_ modules, transitively. Bytecode needed to be abstract-interpreted, the types of values on stack verified, and the types of interface methods that consumed those values verified. The idea was that all of this up-front verification would allow for the later generation of safe optimized code without much effort. That idea didn't pan out as well as hoped. I say none of this to knock Java. At the time of its conception, this truly was the industry's understanding of how to build a robust and secure virtual machine model. Java was truly a groundbreaking technology. WASM benefits from design hindsight. It adopts a strategy of virtualizing the system at a very _low_ level. It's still strongly typed, but the number of types in the system are paltry (a few basic scalars). Its heap model is basically a massive array of scalar words. No garbage collection, no object graph, no weak pointers, complex finalization semantics, etc. etc. If your mind now wanders to the fact that WASM promises support for garbage collection to arrive soon, I'll point out that WASM's idea of garbage collection support amounts to little more than a few hooks to help track "heap pointers" on the stack, to allow for programs to implement their own custom collection approaches. The VM itself does not and will not specify an object graph model or garbage collections semantics over that. WASM's security model is also much more coarse grained and simple. The default system-api surface area in WASM is the empty interface: a wasm module which is loaded and executed and provided no importable modules simply cannot affect anything except its own memory array. Any interaction with the system MUST go through an explicitly provided set of imports that the environment configures and passes in. The VM itself doesn't specify any system API at all. This is developed separately as an independent spec. And here too, the surface area of the API is much smaller. It's modeled after the core Linux/POSIX-ish system APIs, and much easier to reason about. The WASM bytecode is also far simpler. You still need to verify the bytecode, but the types are all scalars, and verifying the usage of module interfaces doesn't require any transitive checks across different modules, like Java does. All this makes the entire system far simpler, easier to prove secure, and faster to execute. Java was one of the first production attempts at making mobile virtual code a reality. It was built by some of the best minds of the time, and it is a fantastic piece of technology. WASM is the result of two decades of hindsight knowledge, engineering experience, and practical experience in sandboxing a browser. It's no accident that while Java was an embedded+systems technology that got adapted to browsers, WASM is a technology that was born in browsers (as a dialect of Javascript!) and is moving out of that realm. WASM was forged in a crucible where downloading and executing random untrusted third party code was expected and routine (web pages). It was able to make better design choices because it was designed in a context where many of those design choices had been forced through sheer existential need. WASM was also designed on an as-needed basis. ASM.JS was a toy project that turned out to be surprisingly adept at executing performant code. Long before WASM existed, ASM.JS was made performant enough to run Unreal Engine 4 on a browser. It was only after ASM.JS had proven itself again and again that WASM was derived as a formalization of it. This bottom-up, engineering first approach is in stark contrast to the JVM's top-down design-first approach. So what's the difference between the two? To summarize: no single thing, but instead a large collection of individual changes that work together as a whole to compose a system that is qualitatively more flexible, more performant, more secure, and easier to reason about. And I'll emphasize again that this is not to knock the JVM or its designers. Those pioneers simply did not have access to the hindsight knowledge, the years and years of practical experience running untrusted code in a production sandbox, years of experience building JIT compilers (for javascript) and understanding what was important for fast execution (it wasn't load-time complexity for sure).