Big web app? Compile it
kripken.github.io
kripken.github.io
It's not encouraging or enticing in any way for me to learn that I can compile my C and C++ to JavaScript, and it'll be "just 2X slower than native code" (but not until "later this year").
I don't consider that an accomplishment. Having to use at least twice the processing power to get the same result isn't something to laud, for example. It's wasteful, not beneficial. It surely shouldn't be something to be proud about.
As an industry, we need to be moving forward. This means doing better than the best we already have. It does not mean only doing things half as well as we can already do, and pretending that we've somehow done something impressive.
Faster program execution means better CPU utilization. More processing resources becomes available for other uses sooner, or fewer resources are needed to begin with.
Faster program execution means better memory utilization. A program that finishes faster holds memory for a shorter amount of time, freeing it up for other uses sooner.
Faster program execution means saving more energy, as a given amount of work can be completed using less processing effort.
Faster program execution means a better user experience, which means more satisfied users.
Faster program execution means the users can be more productive, as they're not waiting as long for processing to complete.
Runtime performance may even be the most important factor to improve upon, given how it impacts so many other factors.
Why dont we just remove all keys from a developer's device besides 0s and 1s so they can program in the fastest computer language!
It's the same C and/or C++ code being compiled in both cases. It doesn't become any easier to write said code, just because it's compiled down to a mangled form of JavaScript rather than a native binary.
Computers serve humans, not the other way around. That means that unless you're optimizing for something that benefits people, you're probably making things worse.
So yeah, if a program is just the same but is twice as slow in a way that harms user experience, then sure, that's bad. But if a program uses twice the CPU but is easier to develop and deploy, that's a win.
For example, if somebody uses the technology to make MAME and its library available in every browser in the world, then that's great, because somebody just enabled a hell of a lot of fun.
Sure, they could try to get everybody in the world to download and install a native copy and save a bunch of CPU time that wasn't going to get used anyhow. But that'd be a big waste of human life, a much more precious resource than CPU time.
Instead of trying to be native in a browser just be native on the plateform you bring the product. The web is not good for everything.
And frankly, if your app is actually worth something, you should have a web version. Not everyone can afford a shiny new iPhone. And that does a thing far worse than harm the UX. It prevents those that would benefit most from using the app.
You make it seem like the battery life is the only thing that matters.
So I agree that if you're doing something where using 2x CPU will make a significant difference and you've already optimized things heavily, then sure, go native. But I'm sure that most apps on my phone are already using 2x the CPU they could be, and I just don't care.
That's what you are missing. Nobody has the resources to build native versions for every available platform, and it means a lot of useful tools and fun stuff is entirely unavailable to large groups of users.
The accomplishment is that we're now close to having a platform that makes most code usable in a much more portable environment. And it's twice as slow now; performance will continue to improve.
By your argument, are you writing everything in assembler? Because modern compilers still leave a lot to be desired and are nowhere near achieving maximal performance.
For starters, they create a ton of stack frames that are unnecessary if you hand-tune an assembly program.
Yet most of us don't program assembly anymore for a reason: It is rarely worth the time.
Then there's the "small problem" of having to develop this in C++, which means you don't have access to all the nice new frameworks that are being developed - AngularJS, emberJS, etc. and have to deal with the joy of dangling pointers, memory leaks, slow compilation time, etc. (even though you might not even need the speed benefit of C/ASM.js). That makes development time a lot longer for no obvious benefits. And of course, there's also the nightmare of debugging cryptic ASM.js code in the browser if something doesn't work.
I can see the point of ASM.js for games or apps where very high performance is required but for web apps I'd rather stick to regular JS.
The beauty of this form of programming is in being able to port large, existing code bases to new platforms with "relative" ease. This doesn't only apply to games (which in large part is the main reason for such things), but to things like a torrent implementation in the browser for example. Or, peer to peer chat ala skype in the browser, all without having to use a centralized server. Applications such as those is difficult write from scratch, but if a porting mechanism exists, it could be a boon to the amount of things you can do online now.
I read the emscripten documentation that you could call pure javascript and pass data back from javascript too. I wondered if you could use Dojo as a widget library replacement for native toolkits like wxWidgets etc. I tried it out and was able to get things working in 2-3 days. And I'm not good at Javascript and have not really tried Dojo before either. I was able to get Sencha to work, but not Sencha Touch. Dojo mobile is working fine as well (but I have to tweak it).
The novelty is not asm.js but using the browser as a Windowing System and a JavaScript library as your UI library. The survey compiler is open source and if you are interested in getting started I and point you to the relevant sources.
What Emscripten enables me is open up the tablet space for surveys with hardly any effort using toolkits like Phonegap.
Btw, you can access the DOM from compiled C++ (and asm.js), for example
http://kripken.github.io/mloc_emscripten_talk/qcon.html#/33
but again, I would not recommend that for general apps. It's useful when you do need to quickly do something in the DOM though, and you are actually writing something that benefits from compiling C++.
With the exception of frameworks like Ocsigen/Eliom[0] and Dart[1] (Eliom being the closest thing to what the presentation hints about), I've never seen any production web apps that have been compiled from languages like Ruby, Python or C (I don't consider desktop applications like Banana Bread a web app). Lack of frameworks and best practices for DOM manipulation seem to be roadblocks.
The presentation didn't list any examples of web apps written in other languages, so I'm forced to conclude that if I have a big web app, compiling it is not the most sensible option.
[0] http://ocsigen.org/overview/eliomapplications [1] http://www.dartlang.org
> I've never seen any production web apps that have been
> compiled from languages like Ruby, Python or C
Ever used Google Groups or Docs? https://developers.google.com/web-toolkit/Thanks for dropping the knowledge.
This seemed like a cool thing, I looked into it a little bit more wondering "How are graphic API calls translated? What about filesystem calls in browser? How do I manipulate the DOM?" and delighted of a new world that would open to me.
And I ended up on my answer: https://gist.github.com/jgranick/5430948
Sure, that is pretty tame CPP code, nothing too hard. And then I looked at the JS demonstration and Chrome decided to give 120MB of RAM to displaying a triangle.
Okay, Chrome may be slow sometimes, things happen,...
curl --silent http://www.joshuagranick.com/examples/simplegl/SimpleGL.js | wc -l
125018
Oh shit.Well, right. The whole "CPP2JS" boilerplate is there.
I won't even entertain the thought of reading past the first screen of 125K lines of computer-generated source code so I'm gonna ask: what is the point to this? There is no native "manipulate the DOM" function in CPP that could be translated to the original JS one and it takes me 125 thousand lines to draw a triangle: what can we gain from this?
Don't tell me "speed", my computer lost it on I/O alone.
1. URL to the source code for the tests and instructions to run the tests to produce the same results.
2. The hardware, OS version(s), and browser versions that were tested.
Otherwise, the difference between Chrome and FF performance as listed in the slides is so great that it seems like it would quickly raise criticism, even though I personally like FF.
The numbers are very dated by now, btw. Real-time information is here: http://arewefastyet.com/#machine=11&view=breakdown&suite=asm...
* Internet Explorer is Windows-only. I run Linux. There are some free VMs now, but you can't benchmark in a VM, it would be unfair. Also, even on Windows, I am not sure if Chakra has a shell version (does it?)
* Safari is OS X only (and again, I run Linux). JSC, its JS engine, has a shell version. This would be great, but the only way to build it on Linux is apparently to build the Qt-WebKit port of WebKit (whereas apparently on OS X it is very simple). I've tried a few times to follow guides on how to do that, and it always fails somewhere in their dependencies. Not sure if the guides are wrong or if something in my distro's Qt deps is not a proper match. A few projects do embed JSC, and are easy to build on Linux, but the snapshots are dated - to benchmark I really want the very latest code, or else it would be unfair to JSC. (Btw, if there is a simpler way to build JSC on Linux, I would really like to know!)
I do sometimes benchmark those two, but it means finding a machine I can borrow for that purpose, which takes time, so it is rare.
(And I don't benchmark Opera because they are moving to V8, which I already benchmark anyhow.)
I am not big on javascript but this question sparked my interest to google it. Apparently, and this is if I parse this correctly, if you apply the .reg file from this StackOverflow answer you can run chakra from cscript.exe which runs js from the command line: http://stackoverflow.com/questions/7167690/what-is-the-progi... - however without this registry hack you'll get some other engine.
If you want a nice GUI tool, Slid.es (http://slid.es) will get you some thing similar. But it's not open source.
This is the realm of Dart and TypeScript and maybe others, but not of C++ -> Javascript compilers!
I am able to easily access the DOM and I am able to pass data back to my c++ functions too (responses to the survey to be stored). However it's not ASM.js that is the novelty for me, but being able to target the browser with almost the same c++ runtime code.
I would not start an entire project like this, but if I discovered I had a computationally bound chunk of code on the browser side, this looks like a nice tool to pull out and attack the problem -- recode the "hot spots" in (emulated) C.
Is there a FreePascal front end? :-)
The presentation is confined to cross-compiling languages (C, C++, Java, Ruby, Lua, etc) to javascript and asm.js. The last ten, or so, slides actually has some content about the trade offs.
My personal opinion is that most of the benefits from "compiling to asm.js" seem to be just removing the JS dynamic types and applying known compiler optimizations.
http://kripken.github.io/mloc_emscripten_talk/banana/benchma...
Forgot to copy it to gh-pages?