News for hackers. Stuff that matters.
Re:Google Introduces Portable Native Client by andyl on Saturday May 18, 2013 @01:28AM (#5728004)
I don't see the need for NaCL when there is asm.js and emscripten. For fast lightweight native sandboxing, now we have docker. NaCL seemed like a great idea, but now it has been overtaken by other initiatives.
Re:Google Introduces Portable Native Client by duaneb on Saturday May 18, 2013 @03:31AM (#5728178)
I don't see the need for asm.js and emscripten. They seemed like a great idea, but it has now been overtaken by PNaCL.

We can all make unsubstantiated claims, and not all of us want to use the ghetto that is modern javascript.

Re:Google Introduces Portable Native Client by zobzu on Saturday May 18, 2013 @05:21AM (#5728342)
I think one big difference is that if right now I play the GL demo on Firefox using asm.js, it works. If I play the same demo on Chrome.. it works.

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.

Re:Google Introduces Portable Native Client by duaneb on Monday May 20, 2013 @01:22AM (#5736046)
This is by far the best argument, but how is the performance of asm.js under browsers other than firefox?
Re:Google Introduces Portable Native Client by vanderZwan on Saturday May 18, 2013 @05:25AM (#5728347)
> Now if I play nacl stuff on ANYTHING else than chrome is does NOT work.

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.

Re:Google Introduces Portable Native Client by karlmdavis on Saturday May 18, 2013 @08:07AM (#5728629)
> That's purely an adoption-by-browser problem.

... 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.

Re:Google Introduces Portable Native Client by zobzu on Tuesday May 21, 2013 @09:25PM (#5748224)
I don't see where the point of asm.js is sandboxing. In fact, that's pretty much beside the point. Sandboxing in NaCL is just a necessity.
Re:Google Introduces Portable Native Client by dietrichepp on Saturday May 18, 2013 @01:58AM (#5728046)
The toolchain is better for embedding existing native applications in the browser with PNaCl. There's a lot of code out there which isn't written in JavaScript, and it would be nice to apply the same sandboxing guarantees. Again, it's not that you can't compile C to asm.js (yeah, emscripten does work), but I think the PNaCl toolchain is just better.
Re:Google Introduces Portable Native Client by TazeTSchnitzel on Saturday May 18, 2013 @08:55AM (#5728732)
Your comment can be reduced to just its final clause. Could you expand on it?
Re:Google Introduces Portable Native Client by coolsunglasses on Saturday May 18, 2013 @03:53AM (#5728213)
The worse tool will win.
Re:Google Introduces Portable Native Client by solnyshok on Saturday May 18, 2013 @08:57AM (#5728738)
I'd prefer to think that most efficient rather than most advanced tools win. look at hammer, axe, knife, nail. they are pure utility expressed as output divided by complexity of use
Re:Google Introduces Portable Native Client by kryps on Saturday May 18, 2013 @02:19AM (#5728080)
Theoretically PNaCL code should be executing much faster than emscripten-generated Javascript. Of course we should do real benchmarks, YMMV and so on.
Re:Google Introduces Portable Native Client by TazeTSchnitzel on Saturday May 18, 2013 @08:57AM (#5728736)
Should it? Both compile to intermediate representations which are distributed, then compiled to machine code by the browser. I see no reason PNaCl should be any faster.
Re:Google Introduces Portable Native Client by zaharpopov on Saturday May 18, 2013 @06:27PM (#5730685)
Well you have benchmarks in that talk - PNaCl is 1.2x native speed. asm.js is ~2x. Single threaded. With multiple threads PNaCl will smoke asm.js since the latter has no threads at all.

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.

Re:Google Introduces Portable Native Client by cromwellian on Saturday May 18, 2013 @03:10AM (#5728139)
NaCL also supports pthreads.
Re:Google Introduces Portable Native Client by jules on Saturday May 18, 2013 @05:57AM (#5728396)
Asm.js doesn't have (as far as I know):

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.

Re:Google Introduces Portable Native Client by pcwalton on Saturday May 18, 2013 @12:26PM (#5729440)
> You lose the light weight.

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.

Re:Google Introduces Portable Native Client by zaharpopov on Saturday May 18, 2013 @06:24PM (#5730682)
> No, an asm.js that supported all of these would still just be JavaScript, which is far more lightweight than PNaCl.

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?

Re:Google Introduces Portable Native Client by pcwalton on Sunday May 19, 2013 @12:31AM (#5731795)
> What makes asm.js "far more lightweight" than PNaCl? What more "lightweight" means here anyway?

It's much simpler than LLVM and reuses the components of the JavaScript engine that already must exist in browsers.

Re:Google Introduces Portable Native Client by zaharpopov on Sunday May 19, 2013 @08:17AM (#5732672)
> 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.

Re:Google Introduces Portable Native Client by RandallBrown on Saturday May 18, 2013 @07:13AM (#5728535)
Why do you want Gotos? There is a small set of problems that is best solved by Gotos and even those can be solved with a less error prone method.
Re:Google Introduces Portable Native Client by jules on Saturday May 18, 2013 @10:19AM (#5728960)
Asm.js is a target language for compilers. That small set of problems that are best solved by gotos includes target languages for compilers.
Re:Google Introduces Portable Native Client by pcwalton on Saturday May 18, 2013 @12:28PM (#5729447)
The Relooper solves this problem for compilers, and it is extremely effective in practice. Besides, you can always solve the lack of goto with code duplication, with no loss in performance.
Re:Google Introduces Portable Native Client by jules on Saturday May 18, 2013 @08:52PM (#5731219)
Except code duplication destroys performance because the instruction cache isn't infinite. I think we can agree that the relooper isn't the optimal solution to this problem...it's a compromise that works pretty well, but its a compromise nonetheless. It also means that you need to involve the LLVM toolchain anyway, just like in pnacl. I don't know if pnacl is a better solution or asm.js, but what I do know is that both are compromise and both have advantages and disadvantages.
Re:Google Introduces Portable Native Client by alexchamberlain on Saturday May 18, 2013 @07:00AM (#5728508)
What does it have then?
Re:Google Introduces Portable Native Client by nly on Saturday May 18, 2013 @07:12AM (#5728534)
Explicit numeric types. Integers in particular.
Re:Google Introduces Portable Native Client by zaharpopov on Saturday May 18, 2013 @04:49PM (#5730415)
Oh no, please please NO.

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.

Re:Google Introduces Portable Native Client by pcwalton on Sunday May 19, 2013 @12:40AM (#5731820)
> 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.

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.

Re:Google Introduces Portable Native Client by zaharpopov on Sunday May 19, 2013 @08:22AM (#5732679)
>It's much simpler than LLVM and reuses the components of the JavaScript engine that already must exist in browsers.

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.

Re:Google Introduces Portable Native Client by ch0wn on Saturday May 18, 2013 @05:15AM (#5728336)
I don't see how docker fits in there. Don't get me wrong, it's a great piece of technology, but it's very platform-specific and has nothing to do with the web as a platform in its current state.
Re:Google Introduces Portable Native Client by andyl on Saturday May 18, 2013 @02:04PM (#5729738)
At one time I was looking at NaCL as a possible solution for lightweight server-side sandboxing.
Re:Google Introduces Portable Native Client by ch0wn on Saturday May 18, 2013 @02:07PM (#5729749)
That's an interesting use case. And you chose docker instead?
Re:Google Introduces Portable Native Client by tomjen3 on Saturday May 18, 2013 @03:08AM (#5728138)
Asm can't do nearly as much code optimizing as pnacl.
Re:Google Introduces Portable Native Client by Groxx on Saturday May 18, 2013 @05:09AM (#5728326)
this seems like a strange assertion to me. why not? you can do amazing things with static analysis and runtime optimization, and that operates on the AST / some intermediate state, not the source code. if anything, higher-level languages (ie, JS as opposed to bytecode) lend themselves to more automatic-optimizations than lower-level ones because intent is encoded better.
Re:Google Introduces Portable Native Client by jules on Saturday May 18, 2013 @10:23AM (#5728984)
Asm.js is lower level than LLVM IR. In LLVM IR the data structures and memory allocation are still visible, in asm.js it's just opaque code working on a giant heap array. For example think how you'd do pointer analysis on asm.js...
Re:Google Introduces Portable Native Client by pcwalton on Saturday May 18, 2013 @12:20PM (#5729425)
The optimizations are already done ahead of time, by Emscripten. There is no need to do them on the client, and doing so just increases compilation time for no reason.

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…

Re:Google Introduces Portable Native Client by Zarel on Tuesday May 28, 2013 @01:15AM (#5778218)
> In fact, shipping the types to the client is harmful, because it increases the download size

To be fair, it's probably negligible compared to the download size impact of representing bytecode in a subset of JavaScript.

Re:Google Introduces Portable Native Client by nly on Saturday May 18, 2013 @07:17AM (#5728541)
NaCL still outperforms asm.js