Asm.js - JavaScript acceleration

Discussion and feedback on Construct 2

Post » Fri Mar 29, 2013 10:51 pm

So there's been some news lately about this thing called asm.js. I don't entirely understand what it is, but it seems to be a way to pre-compile JavaScript so that it's even faster.

http://asmjs.org/

I didn't pay that much attention to it even after Mozilla showed it off by running unreal engine 3 in web browsers using HTML5 - and unreal engine 4 will apparently export to html5 as well - because I've seen new web technologies deployed before that didn't gain any traction with other browser makers, like nacl. However, Google appears to be actually planning to support it as well as Mozilla.

http://news.cnet.com/8301-1023_3-57576903-93/google-shows-interest-in-asm.js-mozillas-plan-for-fast-web-apps/

[QUOTE]Yesterday, Mozilla held a coming-out party for ASM.js, announcing a cooperation with Epic to bring its Unreal game engine to ASM.js. The same day, Google effectively announced a plan to support it within Chrome's V8 engine that processes JavaScript.

"Optimizations should be added to V8 to generate good code for the ASM.js subset of JavaScript," Chrome programmer Kenneth Russell said in a Chrome feature-tracking item for ASM.js. "The implementation cost should be small compared to the potential upside -- the ability to run significant existing code bases with close to the speed of C inside the JavaScript engine."[/QUOTE]

There's no official word yet from Google, but it's sounding good.

I don't know how it works exactly, but since it's apparently backwards compatible for non-asm.js supporting browsers it would be cool if c2 could use it.Arima2013-03-29 22:53:19
Moderator
B
88
S
32
G
33
Posts: 3,005
Reputation: 27,432

Post » Sat Mar 30, 2013 5:20 pm

I've been following asm.js with interest. It looks very cool, but it appears to be mainly for languages which compile to JS - things like Unreal Engine, where presumably they have lots of C/C++ code, and they want to port that to a browser. The JS code that you tend to get with this kind of conversion naturally ends up looking like assembly, since that's what existing compilers do well. You have basically one giant array representing memory, then a lot of JS code that basically shunts numbers around - just like the real assembly you get after compiling C traditionally. Mozilla have figured out how to optimise this special subset of machine-like JS to be within 2x the speed of real assembly. And the very cool thing is it runs on older browsers without specific support; it's all still standards-compliant Javascript, so any browser can run it, although they may be slower at it.

If this was around when we first started Construct 2, it would definitely have been considered as an option. However we already have tens of thousands of lines of JS code hand-written and hand-optimised. I believe this hand-written code already performs very well. If we wanted to go further and take advantage of asm.js, we would effectively have to rewrite the entire engine in another language which compiles to asm.js. This is too much work to justify for a probably small performance boost, and will probably introduce difficult problems around how to handle existing plugins and behaviors. On top of that most games are still renderer-bottlenecked, even on mobile - so it may not even provide any actual framerate improvement at all for many games. So while it's very cool and I'm going to keep an eye on it, I don't think we'll be using it.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Sat Mar 30, 2013 6:30 pm

@Ashley
Thanks for your lucid explanation of asm.js. Wow! - back to the future!

You make a very persuasive point about the real bottleneck generally being the renderer - in any optimisation exercise, it certainly doesn't pay to have a myopic focus on any one part of the end-to-end process.
B
105
S
20
G
12
Posts: 549
Reputation: 20,320

Post » Sat Mar 30, 2013 7:49 pm

Drat, that's frustrating. A way to speed up JavaScript, except you can't use JavaScript to use it. Argh.

Thanks for the explanation!
Moderator
B
88
S
32
G
33
Posts: 3,005
Reputation: 27,432

Post » Sat Mar 30, 2013 8:31 pm

Well if it's truely optimization for other codebases to be translated into ASM style JS, then it should be possible to have JS re-translated into that. However with Ashley's statement I don't see that being a benefit VS improving what they already have created so far with Construct 2 unless they got the time/hired another person to re-write a lot of their existing code. That and compared to their recent blogpost on how the C2 renderer is faster than the Native Construct Classic engine they had before shows how much they've optimized.

Although with the real possibility of high level applications like the Unreal Engine 3 and 4 being ported to ASM.js it'll be easier for traditional programmers to make web apps, in which I think Construct 2 might be better off focusing on becoming the HTML5 replacement for Flash. It's coming along that way pretty well even if it's missing native keyframe animation control. It's easy to use, accessible(free), and can do many things.


Maybe sometime down the line it can be looked at again.Thndr2013-03-30 20:36:01
B
15
S
4
G
4
Posts: 294
Reputation: 3,225

Post » Sat Mar 30, 2013 8:32 pm

This would be the best course to go if Ashley had taken the path of writing C2 in Cpp + OpenGL. It would then be a matter of compiling the engine to JS using Emscripten generating Asm.js code . Right now the idea of Asm.js is to formalize a subset of JS that can be heavily optimized by a specialized JS engine like SpiderMonkey / V8 which can then generate much faster native code from JS . So right now the path is C/C++ -> JS/JS Asm. But there's work with JS -> JS Asm too (LLJS) . So using Asm.js in C2 could be possible in the future, but not right now.Kiyoshi2013-03-30 20:33:29
B
58
S
13
G
10
Posts: 632
Reputation: 12,505

Post » Sat Mar 30, 2013 8:39 pm

@Kiyoshi

Ah, so someone already is making a JS>ASM.js? Sweet.
Well if it turns out good it shouldn't take too much to test it out with C2 output and include it.

Although I'm confused, people say it's backwards compatable, but the article says that V8 should support ASM.js and that browsers to need to support codebases. Are they just talking about NaCL and Dart that Chrome uses as examples and ASM.js would be more optimized on newer browsers that have more direct support for it, but still work fine on older ones?

Not really from a coding background so I can't say I understand too many things on a deep coding level. But I do love how accessible JS and HTML5 is and want to see it bloom to as a competing technology.Thndr2013-03-30 20:41:47
B
15
S
4
G
4
Posts: 294
Reputation: 3,225

Post » Sat Mar 30, 2013 8:42 pm

@Kiyoshi - ah, cool. I hope it doesn't require any major rewrites.Arima2013-03-30 20:43:37
Moderator
B
88
S
32
G
33
Posts: 3,005
Reputation: 27,432

Post » Sat Mar 30, 2013 8:52 pm

ASM.js is new technology, actually is not supported yet to actual browsers, so we will see what happens.
B
96
S
25
G
20
Posts: 3,055
Reputation: 22,644

Post » Sat Mar 30, 2013 9:02 pm

[QUOTE=Joannesalfa] ASM.js is new technology, actually is not supported yet to actual browsers, so we will see what happens.[/QUOTE] So then it's not backwards compatible?
B
15
S
4
G
4
Posts: 294
Reputation: 3,225

Next

Return to Construct 2 General

Who is online

Users browsing this forum: Silverforce, Unconnected, Zebbi and 11 guests