573 points · by blaze33 · 9y ago · 150 comments
Also keep an eye on https://github.com/dcodeIO/AssemblyScript :)
I'm curious how this approach looks from an optimization point of view? I guess emscripten/LLVM can do more optimization than this the AssemblyScript/binaryen toolchain, and when one puts already the effort in for using WASM the goal should probably be to have as much optimization as possible.
For example, the LLVM optimizer can do smart things with aliasing and assumptions about undefined behavior in C code, but for a language like AssemblyScript those might not be relevant anyhow.
But currently the binaryen optimizer is still missing some passes like GVN, so until we add those, that might be noticeable when doing comparisons here.
I'm reading Capability-Based Computer Systems [0] by Henry M. Levy (1984), motivated by wanting to learn about the Burroughs B5000 that Alan Kay has praised multiple times. I've only started to learn about these things and I don't understand the implications, but if I'm reading it correctly, such architectures would obviate the need for web-style safety measures such as process-sandboxing ala Chrome, shader sanitizing ala WebGL, etc, because everything in the system would be safe that way.
[0] https://books.google.de/books/about/Capability_Based_Compute...
More about this: https://en.wikipedia.org/wiki/Capability-based_security and https://en.wikipedia.org/wiki/Capability-based_addressing
"The Burroughs 5000 computer series is discussed by individuals responsible for its development and marketing from 1957 through the 1960s in a conference sponsored by AFIPS and Burroughs Corporation.
In the first session the technical aspects of the B 5000 and 5500 are discussed by a group of managers, engineers, and consultants. Topics include: the state of the industry in the late 1950s; the 5000's predecessors, particularly the ElectroData 101 and 201, B 205, and B 220; factors influencing the decision to produce the B 5000; reasons for designing the machine for ALGOL rather than FORTRAN and the effect of this decision on the computer's development and sales. The group reviews the MCP operating system, PERM, Polish notation, descriptors, stacks, the BALGOL compiler, and other innovations of the computer.
In the second session, the same group discusses the development of the B 5000 into a product, including the effect of the administrative organization on the project; the relations between hardware and software engineers; the interaction of project personnel and upper-level management, field marketing, and customers; the COBOL processor, the head protract disk system; the operating system; ALGOL; and documentation of the computer.
In the third session managers, sales personnel, and customers of the B 5000 discuss Burroughs' product line before the 200 and 5000 series computers; sales training and market reaction to the B 5000; acceptance of B 5000s at Ohio Oil Company and Stanford University; its rejection by the University of Michigan; reasons why the B 5000 was not marketed overseas; and Burroughs' presidents Raymond Eppert and Ray MacDonald."
If you haven't seen it already, I and many better educated people recommend http://www.erights.org/talks/thesis/ (a pleasant read, even if I don't judge it by comparison with other theses) - focuses on distributed computation and language-level capabilities
To be honest: Yes? I would say that is the conventional wisdom in the (small) capability community. I'm sure that oversimplifies carefully-nuanced opinions of course, but, yes.
An example is mentioned here ('angels', 'Power Boxes'):
https://www.cl.cam.ac.uk/research/security/capsicum/
The idea is that capability-based user interfaces do not need to ask those "Yes, get my work done/No, be secure" questions in the first place. That idea will be better tested if they ever take off in more than the isolated areas they're currently found of course.
Capability security has low adoption in part because of the usual catch-22 (adoption breeds adoption), in part because it's a tricky challenge to retrofit, and in part I think because of a failure to communicate the ideas to the best and most influential implementers - exactly why I don't know.
I agree here, that page is the perfect example, all I see is a page full of academic buzzwords and not a "How this works in practice". So we limit what resources an app has access to, that's easy enough to understand, but what happens when an app needs resource x? Does it have to prompt the user or does it have to have to be granted the access at install time? As far as I'm aware those are the only two options.
> The idea is that capability-based user interfaces do not need to ask those "Yes, get my work done/No, be secure" questions in the first place. That idea will be better tested if they ever take off in more than the isolated areas they're currently found of course.
It sounds like it has to prompt users to get permissions:
> This includes a KDE-based PowerBox scheme allowing sandboxed applications to request user-driven file open using standard dialogs.
It will end up being a tool of control and surveillance like always.
This guy says it a bit more eloquently than I can:
It's absolutely not a "tool for surveillance". How exactly are you going to surveil anything with it?
It's not even a replacement for js, or at least it shouldn't be used that way. No GC for instance. And if you are doing any of the silly things mentioned in your link you have no one to blame but yourself. Like accepting binary blobs without source from contractors.
The link eventually admits you can't do a lot of stuff with js and should use native code. Great, lets just have everyone download and execute untrusted and unsandboxed code. In a way that is completely incompatible across platforms. Maybe we can maked them locked behind "walled gardens" with a ridiculous tax while we're at it. Future generations will laugh at us from their completely wasm based PCs.
Or we can always go back to the old way of doing anything interesting with a browser. By making proprietary, vulnerability ridden plugins. Don't you just miss the days of flash and java applets? Because surely that was a much better solution than wasm.
The argument against it linked above is nonsense. Most arguments like this that I see tend to fall into one of these boxes:
1. Using wasm as springboard to argue against something else they don't like.
— e.g. disliking closed source code / source obfuscation / minification is a fair position, but it's not helpful to anyone to pretend that wasm introduces anything different here (as has been pointed out, wast's inclusion of type information actually makes it slightly more readable than minified JS).
2. Arguing against something that wasm could maybe one day become.
— Right now wasm doesn't enable anything you can't already do with asm.js, so the idea that it somehow kills JavaScript or whatever is wrong; anything that can compile to wasm can compile to asm.js. Sure, maybe one day wasm will gain DOM/GC/etc. functionality, but asm.js could just as easily gain a lot of the same proposed features. (And wasm/asm.js aside, plenty of languages already compile to JS quite successfully; this hypothetical future wasm would just make them faster.)
3. Seeming to have only a vague sense of what wasm actually is. I think arguments like #1 and #2 have led to a set of talking points that don't at all reflect reality but sound correct to developers who don't have direct experience with asm.js/wasm.
— e.g. the argument from the linked Lobsters comment that "It solves problems that we don’t have. ... If performance is the important thing you pull on your big kid pants and write C/C++/D/Rust and if ... performance isn’t important, you just write in JS." neatly summarises exactly the point of wasm while somehow trying to frame it as an argument against it.
On (1), you're ignoring the fact that asm.js/wasm/low-level languages are in general harder to reverse than uglified high-level stuff. You can see the details perfectly, sure, but emitted compiled code (say, from Duff's device or something) is a lot harder to back out of than the equivalent minified source code--especially when you see crazy shit like "-O 3" would make. tl,dr; compilation != minification, and acting like they are is at best incorrect.
Your (2) fails to address the entire complaint about wasm (aka asm.js) leading to bad things and ecosystem bloat. You just say "well we can kinda already do it", but fail to address any of the substance of the actual argument I made.
Your (3) misses the point completely about "write in native code" and not "write in something that gets run in an interpreter". Like, you've missed the whole point that if you need performance, you need to be writing something outside the browser, and if you don't need performance existing JS is sufficient.
We'd have been better off fixing Java applets, instead of reinventing the wheel. So now 20 years later, we're cross compiling C...
And ActiveX! you probably repressed the memory of that one, sorry to remind you.
The text form of Wasm looks like it's going to be far easier to read than minified JS.
However I find unsetting how Eich ends up defending WASM by hoping it's not too successful (used only in some hot pathes, not full blob apps.) That's frankly quite ridiculous: I predict a full apps adoption pretty soon. Just wait for more mainstream languages to support it.
The open web in the sense the OP meant has been dead for a while, WASM is just another tombstone.
WASM is not a replacement for javascript, and it's not trying to be. You won't be writing entire applications in whatever you compile to WASM, it's not how it's designed, it's not how it's meant to run, and it's worse in most ways than just compiling your favorite language to javascript (which has been possible for a long time now, but nobody uses it because it's such a leaky abstraction).
The open web is flourishing more than ever, and WASM is keeping that alive with it's "text" mode.
Plus nothing is stopping us from popularizing a trend where everybody puts a publicly discoverable debugging hints file (which would make the disassembly easier to read) with a fixed name next to all wasm files.
By contrast, if in common usage people are only running software compiled to Web Assembly, then:
1. You probably have some work to do to figure out the licensing of the code running in your browser.
2. The ability to look at the program logic for study or reuse is diminished in practice as compared to the early web when you could view source.
2. might be more possible with WASM than it is with minified JS since WASM has a text mode which is very readable.
It's really entertaining watching this subthread, let me tell you.
My experience so far:
Emscripten is quite mature and compiles even very complex C/C++ code without complaining. Statically linking code works fine, while dynamically loading shared libraries is still a bit problematic it seems.
Here's the Github project btw, help is very welcome:
BTW a lot of the power of Python, Ruby and JS comes from the interface these languages provide to existing C/C++ codebases, and I assure you that the binding code to make this work is often far from pretty. As end users we don't care about this though as long as it works.
There's a fairly large class of scientific computing oriented apps where having a widely deployed and fast VM with CPython compatibility would be fantastic. Python (for better or worse) has a large library of open source computational libraries, but shipping an embedded CPython VM is a pain. As an example, I helped advise an undergrad working on a program to calculate collagen fiber orientation for biomedical research labs. Figuring out cxfreeze or other Python packaging systems took longer than writing the actual app.
Unfortunately JavaScript doesn't have broad scientific library support and grad students in non-CS fields don't always have the time to become versed enough in C/C++ to create a usable app. So CPython & associated C libraries ported to wasm could be quite useful... This could apply to R programs as well.
Re: grandparent, just because a project offends your sense of purity doesn't mean it isn't surprisingly valuable for others.
Because it's just Clang with WASM target.
You must not forget that JS does not provide support for many of the things that are required to run a C program (e.g. printing), so emscripten needs to take care of providing alternative implementations for all these things.
With a BBC Micro (6502, 1MHz) I was able to achieve about the same FPS (I was genlocked for UK PAL TV transmission so either 25FPS or 50FPS) but only for a 40x25 grid, using 6502 assembler embedded in BASIC!
Lots of branches in the inner loop, like range check.
https://github.com/blaze33/way-of-life/blob/master/src/js/wa...
No point to benchmark "Hello, World!"s.
CA are great fun to optimise, i've found ways to make them very fast in JS alone, by using pure state machine method with TypedArrays and sliding window algorithm. When letting it skip frames (only drawing when a frame is available) it can go far beyond generations per second... when you get to larger grids the ultimate optimisation is to use FFT, but on smaller ones there is too much overhead and sliding window is way faster.
Algorithmic optimisation is always better, but this demo works for the purpose of showing basic WASM compilation which was the authors intent, there may be an order of magnitude improvement if a different implementation was used.
The point as that for something running safely virtualised (and standardised) in a random browser and on a much larger canvas, the WASM implementation is very impressive.
Game of Life implementations are ideal case studies for optimisation after Michael Abrash's graphics programming columns.
'env': {
'memoryBase': 0,
'tableBase': 0,
'memory': new WebAssembly.Memory({initial: 256}),
'table': new WebAssembly.Table({initial: 0, element: 'anyfunc'})
}
But it is really early on and if the Portable updating SDK is any indication it seems like they want to make it easy to get started.I thought maybe it was some way to write x86 assembly in the browser, but apparently it's a tank game.
For me, the most helpful comment in that discussion was a link to this paper, written by the WebAssembly designers.
https://github.com/WebAssembly/spec/blob/master/papers/pldi2...
Webassembly/Webgl standardization enables the creation high performance replacements for HTML/CSS/dom.
We might end up with applications that are still mostly written in javascript but that call into new webassembly/webgl ui frameworks for rendering instead of into the html/css/dom layer.
This in turn makes functionality that was traditionally very hard to get in a browser/JS environment suddenly very easy to get:
- Cryptographic libraries (e.g. libcrypto)
- Libraries for numerical data manipulation and analysis
- Compression libraries
- Video codecs
- ...
This ability will lead to a paradigm shift (IMHO), because instead of having to reproduce all this functionality in JS (which would be crazy) you can just cross-compile it and use it right away. Also, with WebAssembly, browser vendors can simply focus on providing good and secure interfaces to a limited amount of low-level functions (IO, graphics) while letting the user define the high-level usage of these interfaces. If this works out well I can even imagine this technology spilling over to other domains, because what it provides is essentially a secure, portable, low-level sandbox with a very good performance and a huge installation base.
There will still be a place for native apps of course, but that place will IMO be much smaller.
If there is HTTPS I cannot strip the JS/WASM that does crypto... but you don't need user-side crypto any more.
WebAssembly is the first steps to truly breaking that chokehold, and truly seeing how popular JavaScript the language really is.
Not that I doubt some people do voluntarily enjoy JavaScript, but because of the sheer volume of StackOverflow questions, blog posts, micro-techologies, and other assorted attention bestowed upon the language it can be easy to make the logical jump that JavaScript the language is far more popular (in the satisfaction sense) than is actually so.
Is there anything preventing Python.org from hosting the runtime environment on their CDN that everyone caches locally? Are there security issues from cross domain modules? Worst case, I don't think it would be hard to extend the LocalStorage API to cache modules between domains (perhaps with signed runtimes and a fallback).
x = 1 + '2' //12
x = 1 - '2' //-1
Oh yes, yes we do.Yet here we are, over and over, reading the obligatory complaint in every JS thread about its type coercion and corner cases. Who are all these programmers who can't go a day without tripping over and subtracting booleans from objects, or multiplying arrays by strings, or dividing functions by nulls? Do they suffer this affliction in other languages too? Do they divide by error codes and subtract function pointers from charcodes?
"\t\r\n" == 0 → true
"\t\r\n 16 \t\r\n" == 16 → true
"\t\r\n 16 \t\r\n" == "16" → falseOf the common dynamic languages I can think of, the only ones that do something similar are Perl/Perl6 and PHP, and even they are still saner than JS.
$ $((1+\2))
bash: 1+\2: syntax error: operand expected (error token is "\2")
$ $((1-\2))
bash: 1-\2: syntax error: operand expected (error token is "\2")
$ ruby -e"1+'2'"
-e:1:in `+': String can't be coerced into Integer (TypeError)
from -e:1:in `<main>'
$ ruby -e"1-'2'"
-e:1:in `-': String can't be coerced into Integer (TypeError)
from -e:1:in `<main>'
$ python3 -c"1+'2'"
Traceback (most recent call last):
File "<string>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'str'
$ python3 -c"1-'2'"
Traceback (most recent call last):
File "<string>", line 1, in <module>
TypeError: unsupported operand type(s) for -: 'int' and 'str'
>>> exit()
$ python2 -c"1+'2'"
Traceback (most recent call last):
File "<string>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'str'
$ python2 -c"1-'2'"
Traceback (most recent call last):
File "<string>", line 1, in <module>
TypeError: unsupported operand type(s) for -: 'int' and 'str'
$ perl -e'print 1+"2"."\n"'
3
$ perl -e'print 1-"2"."\n"'
-1
$ perl6 -e"say 1+'2'"
3
$ perl6 -e"say 1-'2'"
-1
$ php -r'echo 1+"2","\n";'
3
$ php -r'echo 1-"2","\n";'
-1
$ racket -e '(+ 1 "2")'
+: contract violation
expected: number?
given: "2"
argument position: 2nd
other arguments...:
1
$ racket -e '(- 1 "2")'
-: contract violation
expected: number?
given: "2"
argument position: 2nd
other arguments...:
1
$ sbcl
This is SBCL 1.3.18, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.
SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses. See the CREDITS and COPYING files in the
distribution for more information.
* (+ 1 "2")
debugger invoked on a TYPE-ERROR in thread
#<THREAD "main thread" RUNNING {1001F0EC33}>:
The value
"2"
is not of type
NUMBER
when binding SB-KERNEL::Y
Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.
restarts (invokable by number or by possibly-abbreviated name):
0: [ABORT] Exit debugger, returning to top level.
(SB-KERNEL:TWO-ARG-+ 1 "2") [external]
0] 0
* (- 1 "2")
debugger invoked on a TYPE-ERROR in thread
#<THREAD "main thread" RUNNING {1001F0EC33}>:
The value
"2"
is not of type
NUMBER
when binding SB-KERNEL::Y
Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.
restarts (invokable by number or by possibly-abbreviated name):
0: [ABORT] Exit debugger, returning to top level.
(SB-KERNEL:TWO-ARG-- 1 "2") [external]
0] 0
* (exit)
$ erl
Erlang/OTP 19 [erts-8.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
Eshell V8.3 (abort with ^G)
1> 1+"2".
** exception error: an error occurred when evaluating an arithmetic expression
in operator +/2
called as 1 + "2"
2> 1-"2".
** exception error: an error occurred when evaluating an arithmetic expression
in operator -/2
called as 1 - "2"
3> halt().
$ elixir -e '1+"2"'
** (ArithmeticError) bad argument in arithmetic expression
:erlang.+(1, "2")
(stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
(elixir) lib/code.ex:170: Code.eval_string/3
$ elixir -e '1-"2"'
** (ArithmeticError) bad argument in arithmetic expression
:erlang.-(1, "2")
(stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
(elixir) lib/code.ex:170: Code.eval_string/3 if(foo === 1 || foo === "1" || foo === true) { ...But no, let's port assembly to the browser instead! Then you get that extra bit out of that one already-overloaded core instead of tapping in to the potentially 15+ other cores on the device!
I'd put forth that that's a far bigger issue to web app performance than HTML/CSS/DOM is. It is for the very heavy web app I've worked on, anyway.
WebAsm's most intriguing aspect as a result is that it has plans to actually add threading along with things like SharedArrayBuffer. That would make locally-intensive & offline webapps vastly more viable.
What could happen, with WebAssembly, is the opposite: A wane in Javascript's popularity.
If the right moves happen, possible. If the wrong moves happen, it will be the second coming of plugins. Languages based on WebAssembly have to be 1st class citizens in the browser infrastructure, otherwise it will be a repeat. This means that debugging has to be transparent. Access to the DOM has to be ultimately the same.
Oh my god, you sent me a flashback to the evil days of the Plugin-Based-Internet...
.. the days of Flash versus Shockwave versus ActiveX versus Java Applet!!
Wanna use TurboPascal to write apps, and target the entire known universe of Web browsers? Go right ahead. You can do that now.
Of course, I'm being extreme, but .. you know .. there are other great ways to exploit WebAssembly as a target, and save yourself a huge amount of cultmind headache by avoiding all of the so-called "higher" layers of the stack, completely.
For example, I'm quite happy writing the most cross-platform'est code, in like, ever, using Lua.
And targeting WebAssembly in this circumstance is a no-brainer.
You'd be wrong, many people would love to move away from to something better. There are many better languages than JS and we'd like to not be limited to one shitty quirky hastily designed language in the browser.
I might work a bit in Rust by itself and compile using emscripten later on the server, but kind of hard to do that if I want to access DOM/canvas/webGL, etc.
https://webassembly.github.io/spec/introduction/index.html
I feel like writing a mini-compiler after glancing through it. It looks closer to a binary AST than an instruction set, though.
I'm already looking forward the day that 32-bit pointers won't be enough for web applications.
Consider: If a good javascript engine like V8 can go as far as being able to emulate hardware, how far can we go with something like webassembly?
All the power to Webassembly!
This brings up a question I've been meaning to ask when the topic came up, because I know almost nothing about GC. How does nim (a GC'd language) compile to a non-GC'd language? And since this is a thing that's possible (unless I'm misunderstanding, which is likely), why does WASM need to add support for GC (http://webassembly.org/docs/gc/#native-gc)?
Binaries are hosted on GitHub but will be downloaded for you
And then you can translate such LLVM bytecode into Webassembly using a tool like Emscripten.
Thus you can compile <insert your favorite programming language> to Webassembly!
Browsers (i.e. Chrome) are already doing this to execute Javascript, for example. Webassembly, to put it in a simplified way, allows you to "bypass" the javascript layer and target directly the virtual-machine. And done in a compatible, well-documented way.
So you can gain in performance, and flexiblity.
You're carting around an entire browser, it's so far from native that it's completely laughable.
As a point of reference: In 1984: MacPaint, 5,822 lines of Apple Pascal, 3583 lines of assembly QuickDraw (dependency): 17,101 lines, all assembly Compiled Size: 0.05MB
Today, Chrome: Number of lines of code: 16 MILLION Webkit (alone): 10.3 MILLION Install size: ~200MB
We have a bunch of people who aren't skilled enough to deal with a real machine who think they're still "near native". Every single thing won't be as fast, or as small, as the underlying hardware can be using toolkits and platforms that have been available for 20+ years (cross platform toolkits and Java both). For god's sake, Java is a portable VM! wxWidgets is cross-platform, and open source!
We accept an operating system in our way as it is, and now we accept not only an operating system, but an entire browser as well? Our computers are faster than supercomputers used to be - why does Photoshop (or ANY program) take so long to load?
We have to go the other direction - start removing all the garbage from computing, keep the best bits, throw the rest out. If you can't hack on a real computer, that's fine - you have the Webassembly sandbox. But don't label it "near native" - it just shows you don't care enough about computers to read about them. I hear that and it sounds like my gradma talking about computers - that same level of understanding. Nana is amazing, but she's not so great at computers. And these people are supposed to be developers?
As for the rest, I don't know how you're measuring. Photoshop runs a lot faster than programs on my Centris 610 did, and sure it's a bloated mess of different programs glommed together but guess what, it does a lot more than smaller programs do. Your comment counts the cost of everything and the value of nothing. You can't click a link and get a brand-new full-featured word processor running on an old Mac in 10 seconds like you can by clicking https://docs.google.com/ But I can run MacPaint in my browser thanks to asm.js https://archive.org/details/mac_MacOS_7.0.1_compilation
We end up with a FrankenMonster of an application, that has a cobbled together persona, built by people who do not appreciate what the machine is actually doing.
There are benchmarks. You can run them yourself.
It'd be great if someone would make (when it's technological feasible) a way to integrate this natively in node, something like:
const wasm = require('wasm-native');
(async () => {
const mymodule = await wasm('mymodule.c');
// use mymodule here
})();- WASM is platform independent, so it can easily be precompiled. Which means just the .wasm module needs to be distributed (e.g. inside a npm package). However WASM modules only have access to things that were already available to JS before (no random C/C++ libraries can be included which e.g. call into the OS, no multithreading, etc.). And the toolchain might be at the moment not yet the easiest to set up.
- Node native extensions have quite good tooling support. Write a binding.gyp and the C++ files and everything works pretty smooth. The native code can also do everything that native code is allowed to do on the platform. However node native extensions are platform specific, which means either precompile them for all target plattforms (and each node release) or deliver C/C++ sources which are always compiled on the deployment plattform at npm install time. They also can't be shared between browser and node plattform.
All in all I think they have slightly different usecases:
- Node native extensions for accessing operating system APIs and other libraries which are not already exposed through nodes JS APIs.
- WASM for making existing C/C++ code including full applications (like games) runnable in the browser
- WASM for making modules which speed up pure algorithms (like audio processing) and which can be used on both platforms.
Go to this link to test it out:
https://linuxontheweb.org/desk?desk_init=bHMgL3B1YjtvcGVuIEF...
The argument in the URL is the base64 encoding of an initialization script that is being passed to the desktop environment. Going to the link in current Edge should just open the "Arcade" app, with nothing else happening.
You should be able to drag-n-drop ".gb" or ".nes" ROM game files from your native desktop right onto the Arcade app window, and it should just start playing. You can also just drop them onto the web desktop to save them there, then just double-click them when you want to play. That way, the file is kept in the site's local storage.
Learn more about how to use the web-based OS here: https://www.youtube.com/channel/UCZkhPP7327fXcSsjD_lt67w
If anybody has wasm-capable Edge or Safari, let me know if you can play the game.