Google Introduces Portable Native Client
techcrunch.com
techcrunch.com
A 2x performance difference means your phone lasts 3 hours instead of 1.5 hours when playing that game. This is a huge, huge difference. Battery-powered devices make performance extremely important.
In fact, shipping the types to the client is harmful, because it increases the download size. This is one of the ways asm.js is, IMHO, a better bytecode than LLVM IR…
To be fair, it's probably negligible compared to the download size impact of representing bytecode in a subset of JavaScript.
We can all make unsubstantiated claims, and not all of us want to use the ghetto that is modern javascript.
Now if I play nacl stuff on ANYTHING else than chrome is does NOT work.
For me its not about having a nice language, it's about being standardized.
Else, I can just provide C binaries, they're faster than nacl anyway.
That's purely an adoption-by-browser problem.
> Else, I can just provide C binaries, they're faster than nacl anyway.
The whole point of both nacl and asm.js was sandboxing.
... which is a pretty big problem, right? Especially since I don't think FF is likely to pick up NaCL unless/until hell freezes over.
1. Good primitive data types (e.g. full width machine integers)
2. SIMD
3. Tail calls
4. Threads
5. Structs
6. Gotos
7. Memory management
Once you add these you lose the supposed advantages of asm.js in practice. You lose the light weight. You lose realistic backwards compatibility because programs using these features will run so slow on normal JS VMs that they're unusable, or in the case of tail calls the program will stackoverflow on a normal JS VM.
No, an asm.js that supported all of these would still just be JavaScript, which is far more lightweight than PNaCl. Besides, these features dovetail with things we want for JavaScript anyway: SIMD, tail calls, full width machine integers are things all JavaScript programs need. By implementing them once and for all we help both regular JavaScript and asm.js.
> You lose realistic backwards compatibility because programs using these features will run so slow on normal JS VMs that they're unusable
No, we are compiling programs that use these already, and they are not too slow as to be unusable. For example, Unreal Engine 3.
What makes asm.js "far more lightweight" than PNaCl? What more "lightweight" means here anyway?
> No, we are compiling programs that use these already, and they are not too slow as to be unusable. For example, Unreal Engine 3.
Do you mean the Epic Citadel demo which runs fine on smartphones. So you made it run more or less smoothly on beefy x86 desktops, how much of an achievement is that? Is it that "OMG I run my game from the 80s inside the browser with HTML5 CANVAS!!!" thing again?
It's much simpler than LLVM and reuses the components of the JavaScript engine that already must exist in browsers.
But LLVM IR has complexity for a reason - you need to be able to generate efficient code from it for multiple architectures. As I mentioned elsewhere, "reusing JS components" is a very unfortunate party line because it keeps us tied to this one JS forever and ever, and we should try to see beyond that.
asm.js is a nice hack and a commendable technical feat, but it's an absolutely horrible way moving forward. Do we really want to look back 10 years from now and see that we picked some crooked-n-twisted subset of JS to be the bytecode to which native code is compiled, just because "hey it's JS and it already works". Have we learned nothing from decades of horrible backwards-compatibility laden platforms?
If one would design a portable bytecode today, would he come up with asm.js? Not in a lifetime (or two). PNaCl is way, way closer to a sane design for such a bytecode. Yes, it has its problems, but these appear to be incremental and can be solved with investment of time and effort (which Google seem to be willing to invest). In its _core_, PNaCl is the right approach to this problem. It uses a subset of the hugely successful and important LLVM IR to represent bytecode. IR that's way more suitable for the task than a subset of JS. And the sandboxing model PNaCl uses also makes way more sense than asm.js's use of typed arrays to represent the heap. Where is your memory model, asm.js? Do you think it's an easy problem to solve? I don't see threads with shared memory coming to asm.js in _years_, while PNaCl already has them. Say what you will, but threads are important. Games use them all over the place, and other applications too.
Remember, speed means battery life for phones and tablets (it's only a matter of time until PNaCl runs on Android, who doubts it?) So 2x native vs. 1.15x native is a huge difference.
Again, as a hacker I can see the coolness of asm.js and kudos to Mozilla for creating it. It's a great interim approach to ensure that native code can truly run everywhere, in all browsers. But looking into the future, I hope it will die and PNaCl (or some derivative of PNaCl) will take over. Even today it lets you compile C++ code and run at nearly native speed with threads on several architectures and several OSes, in a secure way! Other browsers should definitely adopt it. Although I understand if Google doesn't worry much about it - Chrome is the most popular browser today, and its lead is growing. Lack of adoption from other browsers may end up being _their_ problem, not Google's.
Speaking as someone who works with LLVM IR on a daily basis, I really dislike the idea of shipping compiler IR to users. Believe it or not, asm.js is actually significantly closer to the ideal bytecode that I would ship, except for surface syntax.
LLVM IR is a compiler IR: http://lists.cs.uiuc.edu/pipermail/llvmdev/2011-October/0437...
> And the sandboxing model PNaCl uses also makes way more sense than asm.js's use of typed arrays to represent the heap. Where is your memory model, asm.js? Do you think it's an easy problem to solve?
You could implement asm.js in the exact same way. There's nothing stopping you from doing that.
> I don't see threads with shared memory coming to asm.js in _years_, while PNaCl already has them.
Years? Not according to any discussions I've been privy to.
> So 2x native vs. 1.15x native is a huge difference.
I have not verified the PNaCl performance numbers, but I would be surprised if they counted compilation time. The asm.js performance benchmarks do count compilation time. So I suspect the apples-to-apples gap is actually much smaller.
But Google say they used simplified subset of LLVM IR. In addition as far as I understand PNaCl has its own triple which parks down some things like endinaness and pointers size etc. which make IR much more portable.
> You could implement asm.js in the exact same way. There's nothing stopping you from doing that.
Yes, I don't argue you cannot keep evolving JS to be closer to real bytecode, I'm just arguing this in my opinion is not the right way to go. And moreover I think it will fail. People tried retrofit JVM to be bytecode for C/C++ too, and where has this efforts lead?
In contrast LLVM IR /is already/ IR for C/C++. In its full form it's a compiler IR but making it more stable and portable seem like much smaller task than retrofitting all featuers needed for native execution onto JS.
> I have not verified the PNaCl performance numbers, but I would be surprised if they counted compilation time. The asm.js performance benchmarks do count compilation time. So I suspect the apples-to-apples gap is actually much smaller.
Compilation time matters only the first time app is run, Google said. If you have a game or large application, you run it more than once. Since their compilation generates native binary, they just need to load it next time so it's 0 compilation time. I don't know how their first time compilation will compare to asm.js but all subsequent ones are likely better.
However, nowadays asm.js + emscripten seem to be the right direction and Google should adopt it.
At any rate, from the perspective of the developer, it doesn't really make a difference. Either way, developers are interacting with a C/C++ compiler, not directly with the browser engine.
Regardless, it is incorrect that asm.js is first interpreted before being compiled. asm.js is compiled ahead of time exactly as PNaCl is.
I feel like someone is trying too hard to make javascript into something it isn't and shouldn't be. Javascript does it's thing pretty well, why is there no room for other tools in the toolbox?
The contents of Bitcode/Reader/ in LLVM are about 3,000 lines of code alone, and that does not include the definition of LLVM data structures, the validator, etc.
http://mozakai.blogspot.com/2011/11/code-size-when-compiling...
http://mozakai.blogspot.com/2011/11/code-size-when-compiling...
> If the performance of an application is only acceptable on the subset of browsers that implement asm.js then the portability advantage over PNaCL isn't worth that much.
The Unreal Engine demo has proven that, even for games, these limitations don't result in "dog slow" performance on browsers that don't support asm.js.
Not true at all. Now we don't have to postprocess the LLVM into javascript and deal with the pain of debugging completely unreadable bitcode.
PPAPI, and LLVM are not necessarily suitable for cross browser adoption or standardisation. LLVM is a single implementation and so like SQLite, its likely it would not be accepted. It is also not particularly architecture independent nor language agnostic. Low latency polyglot JIT is an open research area on LLVM.
PPAPI is a single vendors view on a suitable API. It focuses on a single vendors needs. The track record isn't there.
"And in the last month alone, we’ve gotten over 2.4x speed boost running this asm.js code in V8, and there’s tons more optimization to come."
Not only that, but it turns out that the mentioned improvements had nothing to do with asm.js at all: https://twitter.com/mraleph/status/334719725617696768
Consider code like this:
int lsize(void) { return sizeof(void *); }
how would this be compiled portably, so that it returns 4 or 8 as appropriate? What would the LLVM bitcode look like?See http://www.chromium.org/nativeclient/pnacl/bitcode-abi#TOC-D...
Or as I will call it, "P-salt".
As in, take it with a grain of salt that Google will support this technology 18-24 months from now after it fails to gain much traction.
Whereas they cannot abandon WebGL if they want to have a standards compliant browser.
We realize there is not yet a simple, comprehensive way to take your Gears-enabled application and move it (and your entire userbase) over to a standards-based approach. We will continue to support Gears until such a migration is more feasible...[1]
How did that turn out?
They filed a Chromium ticket[2] that was moved to an html5rocks.com ticket[3] four months later that was closed as WONTFIX a month after that.
My issue is not that they discontinue projects. My issue is how they often go about it.
[1] http://gearsblog.blogspot.com/2010/02/hello-html5.html [2] http://code.google.com/p/chromium/issues/detail?id=37180 [3] http://code.google.com/p/html5rocks/issues/detail?id=73
[1]: https://github.com/mozilla/rust/blob/master/src/librustc/mid...
[1] http://blog.awilkins.id.au/2012/12/go-in-browser-llgo-does-p...