Kodewerx
https://www.kodewerx.org/forum/

XULRunner, and the speed of JavaScript.
https://www.kodewerx.org/forum/viewtopic.php?f=24&t=7422
Page 1 of 1

Author:  Parasyte [ Mon Nov 08, 2010 8:58 pm ]
Post subject:  XULRunner, and the speed of JavaScript.

When I first began re-re-writing Syndrome in JavaScript, I wasn't sure what to expect so far as rendering speed. In C, the first stage in Mega Man 7 could be rendered in 0.009 seconds on a ten-year-old Athlon XP 2600. That's incredibly fast. How does it compare in JavaScript?

Well ... the first attempt was not all that impressive. In fact, it was downright disheartening at 2.023 seconds on Gecko 1.9.1 running on a 2.8 GHz Core 2 Duo.. After some major refactoring, it got a good bit faster at 0.486 seconds on Gecko 1.9.2. Still a few orders of magnitude away from the raw performance of C.

By doing nothing more than upgrading to Gecko 2.0beta, The same code base renders in 0.264 seconds. Removing just a single for-loop that pre-filled an array with zeros brought it down to 0.188 seconds. Hacking the pixel-pushing code from plain old JavaScript arrays to the brand new JavaScript Typed Arrays increased the speed even further, down to 0.16 seconds. And doing the same kind of hack on the palette cache brought it down to the current 0.15 seconds.

At this point, it is still ~17x slower than the raw C drawing code. But there is still many more opportunities for optimization. Converting many of the array buffers to JS Typed Arrays will likely help dramatically, still. The ROM buffer would probably show the biggest improvement, along with the accessor methods for pulling different data sizes from the buffer. And Web Workers can push the actual rendering into background threads making the actual drawing look like it completes instantly. And of course, for pure überspeed, writing a dynamic library in C that does pixel-pushing, and calling into it with js-ctypes.

Still, 150ms to draw a 4864x768 bit-map using only JavaScript is incredible! Gotta hand it to Mozilla, they've done really well. And it's only going to get faster! Gecko 2.0 is still just in beta (planned release is sometime in early 2011). It won't have a great deal of performance improvements by then, but there's still planned work that will go into the JavaScript engine in the future. It's a good time to be a web developer transitioning to desktop application development. ;)

Author:  James0x57 [ Mon Nov 08, 2010 9:17 pm ]
Post subject:  Re: XULRunner, and the speed of JavaScript.

_awesome_

Page 1 of 1 All times are UTC - 8 hours [ DST ]
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/