JavaScript – ready or not.

JavaScript Performance

There have been some very promising improvements in JavaScript performance, but exactly how good is it? It turns out, that there is a pretty easy way to work this out – thanks to haxe.

Haxe allows the same code base to be compile to Flash, JavaScript, neko and cpp. The graphics is handled differently – Flash uses its plugin, JS uses canvas and neko is using the NME library, running opengl. To compare these, I’ve chosen the Physaxe library, which is optimized for all these platforms, and can give a feeling for an app that has a computational and graphics load.

Into this mix, I will add another interesting option: The V8 JS engine, running using the NME library in opengl mode. This cross-over mode is actually quite easy to implement because of 3 stars aligning: 1. The NME library has a external interface that uses opaque handles that map very naturally to the v8::Value *. 2. The haxe compiler makes it possible to program JS without losing your mind, and all the existing library code is valid for this target. and 3: The Google V8 JS engine has a clean API that makes it easy to embed (you would almost think they designed it that way – dispite the frugal documentation).

The benchmark I have chosen is the “Pentagonal Rain”, which is nice and stressful for the CPU. You can try for yourself – use the ’5′ key to switch to this demo.

Engine FPS
Neko/nme 9
Chrome 4.1, JS 11
Opera 10.5.3, JS 18
V8VM/nme 23
Flash 37
CPP/nme 130

So as you can see, the V8VM option is actually quite viable as a scripting vm. Since there is a lot in common between neko, v8vm and cpp haxe targets and plugin architectures, it should be relatively straight forward to switch between them.

The JS demo can run on the iPhone. But just because you can do something, it doesn’t not mean you should \- at about 2 FPS on the title screen, I can’t imagine how slow it would run in the Pentagonal Rain demo. And probably not great for your battery either :)

This entry was posted in flash, hxcpp, neko, nme, Result and tagged , , , , , , . Bookmark the permalink.

11 Responses to JavaScript – ready or not.

  1. Du Song says:

    Not sure why but Chrome 6.0-dev, Safari 4.0.5 and Opera 10.53 all show steadily 21-23fps on my Macbook Pro.
    Firefox 3.6 is slower, only ~14 fps.

  2. blackdog says:

    Thanks, that’s interesting to see, I felt that V8 would be quicker than neko but not by such a substantial margin.

    Are neko’s days numbered?

  3. Tarwin says:

    Nice tests. I found that Opera is faster not in it’s JS engine, but more in it’s Canvas rendering speed.

    I did a test a while back (sorry can’t find it online) where I exported a black and white movie as arrays from Flash and made a simple Javascript to play it. Firefox was way too slow, Chrome played it OK, and Opera sped along at over 30fps from memory – and that was even when zooming the stage in and out!

  4. Pingback: neko/v8 performance « blackdog

  5. CauĂȘ says:

    Hey Huge!

    Great post! Can you post the v8vm code you used to bind neko dlls to the vm? I’d really love to play with it, also! : )

    Thanks!
    CauĂȘ

  6. Huge says:

    Hi,
    I have put the code here.
    But be warned, it is very raw and requires you to do some compiling – unless you can use the binaries provided in the win32 distro, and just recompile the haxe.

    Hugh

  7. robo says:

    I want to ask if js canvas not support current haxe mouseEvent?
    and when it can be build for google android system?
    thanks .

  8. horseman says:

    Now that Flash is out on mobile, I thought I’d compare these two physaxe samples on Droid 2

    Droid default browser JS
    2 – 5 fps

    Droid Flash 10.1
    20 – 40 fps

    Opera Mini browser JS
    -Frozen-

  9. Liburn says:

    I couldn’t believe Neko/NME is getting only 9 FPS, so I made test on my old laptop (VAIO, Intel Pentium M 1.7 Ghz, Intel GM/GME crappy graphics). Result:

    Neko/NME ~20 FPS
    Firefox8.0 ~20 FPS
    Flash 11.1 ~42 FPS
    V8 ~40-50 FPS (highly oscillating)
    CPP ~90 FPS

    Unfortunately, your tests are missing average FPS measuring.

  10. Huge says:

    Ok, maybe it’s not so bad. Perhaps neko had a performance upgrade.

  11. Ivan Kuckir says:

    JavaScript demo has 20 fps, because in your code (on line 3480), you have
    var fps = 20;
    Here is my JavaScript physics demo with 50 objects, 60 fps using 5% of CPU.
    Still don’t understand how people can take those results seriously.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>