Slashdot Mirror


Asm.js Gets Faster

mikejuk writes "Asm.js is a subset of standard JavaScript that is simple enough for JavaScript engines to optimize. Now Mozilla claims that with some new improvements it is at worst only 1.5 times slower than native code. How and why? The problem with JavaScript as an assembly language is that it doesn't support the range of datatypes that are needed for optimization. This is good for human programmers because they can simply use a numeric variable and not worry about the difference between int, int32, float, float32 or float64. JavaScript always uses float64 and this provides maximum precision, but not always maximum efficiency. The big single improvement that Mozilla has made to its SpiderMonkey engine is to add a float32 numeric type to asm.js. This allows the translation of float32 arithmetic in a C/C++ program directly into float32 arithmetic in asm.js. This is also backed up by an earlier float32 optimization introduced into Firefox that benefits JavaScript more generally. Benchmarks show that firefox f32 i.e. with the float32 type is still nearly always slower than native code, it is now approaching the typical speed range of native code. Mozilla thinks this isn't the last speed improvement they can squeeze from JavaScript. So who needs native code now?"

6 of 289 comments (clear)

  1. Re:"So who needs native code now?" by MightyMartian · · Score: 4, Insightful

    What a bizarre statement. Of course it's programming. It may not be very elegant programming, but then again, the bulk of C code I've seen in my years in the business isn't terribly elegant either.

    --
    The world's burning. Moped Jesus spotted on I50. Details at 11.
  2. Re:"So who needs native code now?" by phantomfive · · Score: 5, Insightful

    Correct this to any real programmer. I'm tired of web designers being colluded with actual programmers, scripting isn't programming.

    Heh....typing isn't programming. If you aren't connecting patch wires on an accumulator bank, it's not worth doing. You get more efficiency that way too!

    --
    "First they came for the slanderers and i said nothing."
  3. Re:Or anything running in a VM by bberens · · Score: 3, Insightful

    That depends a lot on what you're doing. It costs about $125/hr for me to optimize my code. Every 8 hours spent optimizing is $1k down the drain and you can buy an entry level server for that price. If it's running on one or two VMs it's probably not worth my company's time to optimize it vs buying more hardware. Conversely if I'm Google a 1% optimization could mean literally thousands of servers. I mean, don't get me wrong. I pay attention to memory allocation and CPU optimization as I'm coding, but only to the level of not making unnecessarily egregious use of resources. Pretty much anything beyond that is a waste for most of the projects I work on.

    --
    Check out my lame java blog at www.javachopshop.com
  4. Re:Or anything running in a VM by zippthorne · · Score: 5, Insightful

    Another question is why we need to duplicate an entire operating system to encapsulate applications. If you have 100 things that need to run on a machine why should you need to also run 100 entire operating systems? Something is wrong with the way we're designing servers.

    --
    Can you be Even More Awesome?!
  5. Re:"So who needs native code now?" by Anonymous Coward · · Score: 2, Insightful

    Try doing WHAT in C? The idiot who wrote that code doesn't know how to comment!

  6. Re:"So who needs native code now?" by darkHanzz · · Score: 2, Insightful

    In C++ it'd come down to a lambda function and std::swap, I don't see how that's less 'elegant'.