12 ms·
Asm.js in Firefox Nightly
- jlongster 14y agoI am so excited about it. It's worth noting that I'm porting LLJS to compile to asm.js already, and I have basic code already working with it: https://github.com/jlongster/LLJS https://github.com/jlongster/LLJS I plan on polishing it up tonight and publishing/blogging about it tomorrow.
- smrtinsert 14y agoWow, your project looks amazing. My evenings plans just got cancelled.
- jlongster 14y agoIt's worth noting that LLJS itself came from a few smart guys from the Mozilla Research team. I work for Mozilla but as a web developer and I'm just doing the port. The asm.js branch is highly unusable as is, but it should be somewhat stable tomorrow!
- MatthewPhillips 14y agoI remember reading about this on HN a while back and wondering why anyone would want to use it, but now it totally makes sense. I don't want to go back to writing C/C++ but if you could write your app in JS, and then do the tighter "inner loop" parts in LLJS... that sounds really enticing. I'll be following the project closely.
- jlongster 14y agoI wasn't convinced of it either at first. You can get around a 5% speed increase with compiled code (because it uses typed arrays and other things which are heavily optimized), and I played around with it for a game, comparing it to emscripten and raw js: https://github.com/jlongster/js-lljs-c-benchmarks/ https://github.com/jlongster/js-lljs-c-benchmarks/ When I heard of asm.js I immediately realized that I wanted LLJS though. You're absolutely right that it could turn into something which helps you write only parts of your app in asm.js. Everyone should note, however, that you usually don't need this. Javascript is still highly performant. This is just helpful for things like incredibly complex 3d games, number crunching, etc.
- kibwen 14y agoThis post mentions IonMonkey, which is the newest enhancement to Firefox's Javascript engine. According to http://arewefastyet.com/ http://arewefastyet.com/ , it appears to be doing pretty well so far (red is old Firefox, purple is current Firefox, black is future Firefox, green is Chrome, lower is always better). Excited to see what'll happen once OdinMonkey gets added to the mix.
- evilpie 14y agoNothing, at least not to the benchmarks currently on awfy. You need to opt-in into OdinMonkey optimizations with "use asm". And of course these benchmarks don't do it.
- mfunk 14y agoSmall correction: purple is current Firefox, not red. Red is not shipped in any build.
- kibwen 14y agoAh, I had no idea that IonMonkey had made its way to the stable release. Very cool.
- benaiah 14y agoI think that compile-to-JS languages are going to explode in popularity even more than they already have when they can compile to an optimized asm.js. I might be misunderstanding its impact, but I'm hopeful.
- kayoone 14y agoit doesnt really change the game for traditional web development though. Thinks like GWT might be faster with asm.js but it didnt take off for other reasons than speed.
- mindcrime 14y agoI approve of this link, just for the Amon Amarth reference! That said, I'm somewhat excited about this, but also discouraged by the lack of commonality between major browsers in this regard. Now Firefox has asm.js, Chrome has NaCl, and Microsoft has ??? and Opera has ???. Uugghh... Still, anything that stands to make the web experience faster and more useful is a good thing, I guess..
- aeosynth 14y agoAny browser can run asm.js code, that's the whole point; it doesn't need special support.
- kibwen 14y agoThe only reason that I'm excited for asm.js is the fact that it's cross-browser, since it's literally just a subset of JS. Theoretically something transpiled to asm.js would be executable even in IE6, though I'd really like to see someone try.
- mindcrime 14y agoAah, OK. I actually didn't realize that, my bad. I was thinking of it as something analogous to NaCl. That's good to know, then. Hopefully this makes things better for everybody!
- cromwellian 14y agoExecutable != useful though. This breeds a false sense of portability. If Firefox is the only browser that implements asm.js, it'll have about the same issues as Dart or NaCL. That is, Dart also compiles to JS, but if Dart2Js were 6x slower on Firefox than Chrome, no one would be cheering, and in fact, this is a complaint Mozilla themselves raised in the beginning. If I'm writing a game in C and compiling it to asm.js, and it's gonna run 6x slower everywhere else, I'm effectively developing it for Firefox only no differently than if I had compiled C to NaCL/PNaCL. For this to be effective, it has to be cross browser. At least, Mozilla and WebKit/Chrome.
- 14y ago
- hosay123 14y agoActual numbers from the Groups link at the bottom: So I discovered from Alan today - asm.js was everything I hoped it would be. One of the more intensive examples in OpenSCAD (https://raw.github.com/openscad/openscad/master/examples/example006.scad) gave me these metrics: Native: 402 seconds, asm.js version: 605 seconds, asm.js version in Chrome: 3724 seconds And the exciting part? Backwards compatibility even with IE6, forwards compatibility with optimizations that haven't been invented yet – and no 80s era blob+VM architecture in sight. All without inventing any half baked new language, file format, virtual machines or whatever else, and building on a language spec that's already an ISO standard. Eat your heart out Native Client!
- masklinn 14y ago> Backwards compatibility even with IE6 As long as the runtime is ignored though, if Chrome gets a 6x perf hit I can't even imagine how unusably slower IE6 would run.
- hosay123 14y agoPerhaps for your OpenGL games, but for some business application originally written for VB4 that basically draws a bunch of forms and puts stuff in a database, that's more than fast enough for some compiler that took VB4 and turned it into JS. This is basically the reason d'etre for NaCl as far as I can tell: it was at various points advertised as for games and other 'high performance' stuff, but the more probable commercial reason for it is to leverage companies on to a non-Microsoft platform through an easy migration path. So I think the hypothetical VB4 compiler comparison (or a million similar "business app migration" examples) is pretty fair. [edit: per subsequent comment, the notion that GC somehow can't be implemented is nonsensical]
- ahoge 14y agoVB uses garbage collection. You can't compile it to the JS subset of asm.js.
- 14y ago
- xal 14y agoASM.js is easily the hack of the year. Every hacker should walk around with a smile on their face today.
- jahabrewer 14y agoSorry I'm late to the party. Could someone explain what this is? All I've found in search is talk about how much faster it is. Devs write code in C/C++ and target js? Is that it?
- masklinn 14y agoasm.js is a low-level statically typed subset of javascript, roughly equivalent to C (that's not exactly it but close). As a result, it can be AOT-compiled to machine code rather efficiently and lead to excellent performances with special support, while still being 100% compatible with browsers providing no special support (as it's a subset). The idea is to make it an efficient (if low level) language to use out of the box, and an efficient compilation target for higher-level non-javascript languages (C and C++ are used for comparisons but e.g. clojurescript or elm could compile to asm.js as well instead of their current javascript target). Basically, as the name implies asm.js tries to be an assembly for the web, but a backwards-compatible one (as opposed to NaCl)
- pfraze 14y agoIt's a subset of Javascript that constrains the feature-set so that optimizations can be applied. This post is announcing that Firefox nightly has added those optimizations, so you can use the spec and get the speed bump. It's particularly good for transpiled languages, as they can easily target this subset. http://asmjs.org/faq.html http://asmjs.org/faq.html
- lmkg 14y agotl;dr Asm.js is a subset of JavaScript that is easy to optimize. It's sort-of a competitor to NaCl, but its basic premise is that a specialized runtime is just a bonus, not a requirement, to run asm.js files. Any and all asm.js code has the same semantics as regular JavaScript. This is the most important thing about it--it already runs, everywhere. If a browser gets an asm.js runtime, the only thing that changes is speed. Asm.js code is very, very low-level. Pretty much the only operations supported are statically-typed arithmetic, and array load/stores. It doesn't use any dynamic behavior--the closest it has, is arrays of functions that must have identical signatures, so that you can implement vtables yourself. Its resemblance to assembly is intended to make it a better compiler target.
- rayiner 14y agoWorse really is better. Asm.js fulfills the promise of formats like ANDF, except by going through one of the shittiest intermediate languages you might imagine.
- MatthewPhillips 14y agoAlready adopted is better than not already adopted.
- rayiner 14y agoHence my reference to: http://www.stanford.edu/class/cs240/readings/worse-is-better.html http://www.stanford.edu/class/cs240/readings/worse-is-better...
- jahewson 14y ago> except by going through one of the shittiest intermediate languages you might imagine. Visual Basic?
- DannyBee 14y agoVB's pcode was actually not horrible ....
- fosap 14y agoOk, everybody, Javascript is over. Now everybody will be able to use their favorite language and chances are that it will be faster.
- cromwellian 14y agoHoisting my comment up: Executable != useful. Saying asm.js runs in VMs that have no special support for it breeds a false sense of portability. If Firefox is the only browser that implements asm.js, it'll have about the same issues as Dart or NaCL. That is, Dart also compiles to JS, but if Dart2JS were 6x slower on Firefox than Chrome, no one would be cheering, and in fact, this is a complaint Mozilla themselves raised in the beginning (that if DartVM has an enormous performance advantage compared to Dart2JS it would make other browsers look bad and fragment things) If I'm writing a game in C and compiling it to asm.js, and it's gonna run 6x slower everywhere else, I'm effectively developing it for Firefox only no differently than if I had compiled C to NaCL/PNaCL. For this to be effective, it has to be cross browser. At least, Mozilla and WebKit/Chrome. (honestly, without WebGL support, I don't think it helps IE with games anyway)
- kevingadd 14y agoI don't think you understand asm.js. It's cross browser. If it happens to run slowly in v8 that's just because v8 is poor at optimizing JS that makes heavy use of typed arrays (which is already the case in some scenarios, demonstrated by Chrome's performance being inferior to Firefox's on many non-asm.js benchmarks).
- cromwellian 14y agoDid you fail to understand my point? Dart is cross browser too. You write a Dart app, it runs in the DartVM on Chrome, and runs as JS on Firefox. If Firefox runs it slowly, it's because Firefox is worse at recognizing the patterns of transpiled Dart code, right? I could define my own spec, "dartjs.js" which has specific style of writing JS that a VM could be tuned to recognize. Same issue. I'm not attacking ASM.JS here, I'm just pointing out that if it isn't supported by other browsers, no one seeking high performance can depend on its portability in that regard. None of this makes any difference to a developer who is trying to ship a game, he has to deal with the world as it is. And if the world is Firefox has asm.js, and Chrome has NaCL, then they will write their games in C/C++, and use Emscripten+Asm.js for Firefox, and NaCL for Chrome, so NaCL still won't go away. The point is, rather than just dumping a new spec and VM module on the community, it has to be a cooperate effort so that there's a stable platform to target that isn't a pathologically bad performer elsewhere.
- macspoofing 14y agoThis is exciting. I hope Google (and eventually Microsoft, Opera and Safari) jump on this.
- vmind 14y agoSlight offtopic: if anyone installed Nightly to have a look at this, and the UI is scaled strangely (might just be a windows thing related to HiDPI) you can set the devPixelsPerPx in about:config to 1.0 to get the scaling back to normal.
- natmaster 14y agoI'd like to see a python->asm.js compiler. Then I throw that in my resource generation pipeline and I am a happy programmer.
- dnu 14y agoBut could Python really take advantage of asm.js? I think that this is more useful for compiling statically typed languages (C/C++/... maybe TypeScript?) to JavaScript.
- whatshisface 14y agoIt's been said elsewhere, but you musn't forget that the python interpreter itself must be compiled. The pypy project is a python interpreter written in a restricted subset of python (rpython), and it would be doable to make the rpython compiler output asm.js.
- haydenj0nes 14y agofriendly reminder that google's dart dev team has made claims that dart is already 30% faster than js, and they plan to release VMs capable of surpassing 100% faster than js, so yeah. keep in mind that if asm.js is half of native speed, dart is capable of bridging the gaps of js.
- cpeterso 14y agoHow will a fast Dart VM help Firefox and IE users?
- haydenj0nes 14y agoI don't understand how that's supposed to make sense. A competing product doesn't have to take care of its other competitors.
- zobzu 14y agoyou seem to really care about standards! so basically, ActiveX is faster than dart. you should probably use that. you know. its actual native performance:)
- pekk 14y agoYou can't blame Google if Firefox and IE have no interest in supporting Dart natively.
- lubos 14y agoThis is huge. Never heard of Asm.js until now but this is the first time I'm really excited about Javascript. I feel like dropping everything right now and start playing with this.
- neeee 14y agoQuick test on the BananaBread benchmark: Without asm.js preload : 53.698 seconds startup : 11.904 seconds gameplay: 369.86 total seconds gameplay: 196.538 JS seconds With asm.js preload : 55.513 seconds startup : 7.093 seconds gameplay: 75.848 total seconds gameplay: 54.318 JS seconds
- rsofaer 14y agoThis could be very useful for getting numerical and other high performance code into the browser.
- sowhatquestion 14y agoFrom the comments: "This can give a second life to the JS backend of PyPy." That would be incredible. Any PyPy devs care to comment on this possibility? :3
- surrealize 14y agoThere are some speed comparisons in the comments here; it would be really nice to see some compiled-code-size comparisons between native and asm.js.
- pcwalton 14y agoSee http://mozakai.blogspot.com/2011/11/code-size-when-compiling-to-javascript.html http://mozakai.blogspot.com/2011/11/code-size-when-compiling... Comparable with native after you gzip. Note that this wasn't asm.js, however, just vanilla Emscripten output. asm.js output will be somewhat larger due to the strict type system.
- surrealize 14y ago> asm.js output will be somewhat larger due to the strict type system. That's the part I was wondering about. I'm hoping that we'll see rust compile to asm.js! ISTM that there's some similarity between web worker "transferable object" semantics and rust unique pointer semantics. If ES "binary data" objects end up being "transferable objects", maybe rust unique pointers can map onto transferable objects in rust tasks that are compiled to asm.js and run as web workers.
- zobzu 14y agoTried the demo in Chrome and FF-nightly like everyone, and like everyone I guess, I was really impressed. it's visually twice faster in Firefox. Firefox seems to have come a long way.
- kayoone 14y agoFor traditional web development this wont change too much does it? i mean you could write the business logic of your app in whatever compiles to asm.js(which in pratice is mostly done server-side) but in the end you would still do DOM manipulation using JS or not? makes alot of sense for rich apps and games though.
- manmal 14y agoYes, I would love to see an adapation of MVC frameworks like Ember and Angular to use asm.js - not really sure if it's necessary though, since they are already that fast.
- afshinmeh 14y agoNice! I really need an environment to test asm.js.
- Kiro 14y agoHow does this affect us "normal" JavaScript developers who don't know anything about low-level stuff?
- shardling 14y agoSome of your libraries might get a little faster.
- endemic 14y agoFrom what I can see, it means you write your code in another language, and then it is "compiled" into performant JavaScript. Basically it would create much more efficient JavaScript than you could write yourself. Nothing to stop you from continuing to write regular JS, though =]
- jlebrech 14y agoWhy can't we just have a universal bytecode that can be interpreted by any browser.
- cdi 14y agobecause politics, control, money, power.
- jlebrech 14y agochrome compiles javascript into an intermediate language already, they just need to allow that intermediate code directly from a script tag.
- jlebrech 14y agochrome compiles javascript into an intermediate language already, they just need to allow that intermediate code directly from a script tag.
- camus 14y agoJust learned about asm.js , awesome ! but other browser vendors need to support it ! great work again -moz ;)