Inside Mozilla's New JavaScript JIT Compiler
An anonymous reader writes "IonMonkey is the name of Mozilla's new JavaScript JIT compiler, which aims to enable many new optimizations in the SpiderMonkey JavaScript engine. InfoQ had a small Q&A with Lead Developer David Anderson, about this new development that could bring significant improvements in products that use the SpiderMonkey engine like Firefox, Thunderbird, Adobe Acrobat, MongoDB and more.
This new JIT infrastructure, will feature SSA compiler intermediate representations which will facilitate advanced optimizations such as type specialization, function inlining, linear-scan register allocation, dead-code elimination, and loop-invariant code motion."
What's different between IonMonkey and JaegerMonkey (the last engine I thought)?
My first Journal Entry ever, in 8 years! http://slashdot.org/journal/365947/aphelion-scifi-fantasy-horror-poetry-webzine
I'd be interested to hear why the Mozilla developers don't use an existing compiler framework like LLVM, which already implements many advanced optimization techniques. I am aware that JavaScript-specific problems need to be dealt with anyway, but it seems like they could save themselves a lot of hassle in things like register allocation etc. Those are not so interesting problems that are handled by existing tools like LLVM quite well, so why not use that?
Damn, Mozilla changes JIT engines like every year. Why should be believe this one will last any longer than all the others they have tried?
Javascript is a poorly designed language that is hard to JIT and I imagine that's why we keep seeing people trying to redo things better than the previous JIT engine. It's damn near impossible though, just micro-fractional improvements and a whole lot of wasted effort.
Meanwhile things like LuaJIT offer a Javascript-like scripting environment with damn near the performance of native C applications. Pretty much all done by one guy.
Lua is what Javascript should have been. It's dynamic, simple, and fast (partly because it's so simple). The language itself is so much cleaner than Javascript which makes it easy to parse and optimize while still giving you all the power.
you would have love fortran
I have to imagine that there are some sneaky things you could do if allowed to lie to the compiler about what variable types you are using... Obviously, you could check; but guessing and checking takes longer than just checking.
That sounds like an incredibly fragile idea. That said, a lot of work is being done to add Type Inference to the JaegerMonkey engine, which performs static analysis to determine type information.
Why don't you use a type declaration?
thegodmovie.com - watch it
Now javaScript is so fast perhaps other interpreted languages would be "compiled" to JS. I am thinking of Perl6 for one.
And once all that nice code is run through a javascript obfuscator/compressor that renamed all the "str" variables to "a" "b" "c" etc, what then?
If I have been able to see further than others, it is because I bought a pair of binoculars.
This looks a lot like what PyPy is currently doing
OK. Let's look at http://code.jquery.com/jquery-1.5.2.js very quick. This isn't even a minified version; just the original source. Pretend like you don't know what jquery is doing. The first few functions with arguments here:
> function( selector, context )
What are the types of those?
> function( selector, context, rootjQuery )
And those?
> function( num )
And that one? Hint: the function expects it to be "null" or at least "undefined" sometimes.
> function( elems, name, selector )
And that? Note that the function itself is not sure what to expect in |elems| and has different codepaths depending on what it finds there.
The point is, going from name to type is not really that easy.
Worse yet, "type" in this context also means what JS engines variously call "shape" or "hidden type": two instances of Object are considered the same type if they have the same properties in the same order. Telling _that_ from a variable name is pretty hard.
Didn't Mozilla cry bloody murder when IE9 was discovered to perform dead-code elimination claiming it was "cheating" because it made some outdated JS benchmarks finish in 0 time?
So what would be the prefix for variable 'anonymousUser', which holds an object created from the User prototype and with a couple of custom methods added dynamically?
Dilbert RSS feed
Optional type annotations (a la ActionScript3) were considered for JavaScript in the ECMAScript4 standard, but the committee decided it didn't want to go in that direction.
I think its time that Javascript and HTML get transmitted in a pre-compiled format, like Java.I'm sure the compiled file will be smaller than its mark-up counterpart, and would run faster in the browser since the browser won't have to analyze the mark-up before "compiling it" and rendering it. Plus, it might help people code their web-pages to standards if the compilers won't compile their half-assed HTML.
Type annotations are only useful for documentation, and for some sanity checking (although type theory is not expressive enough to catch any interesting classes of programmer error). The StrongTalk team discovered that they got much more accurate information from type feedback than they did from programmer-provided type annotations. They created a dialect of Smalltalk with explicit type annotations. Their VM was the fastest Smalltalk implementation at the time by quite a large margin, and they found that they got no performance benefit at all from using the user-specified type information.
I am TheRaven on Soylent News
I wonder how do javascript engines optimize hash table lookups. Especially since it is faster to access a member of an object than to access a variable of an outer function. It seems to me that the former requires a hash table lookup with a string key while the later suffices with a pointer into the closure of an outer function and the offset of the variable.
and I still cannot run a mozilla javascript environment inside IE, Opera, or Chrome.
You think I'm joking but I'm plain serious. Why are we so dependent on each particular javascript implementation?
If Pandora's box is destined to be opened, *I* want to be the one to open it.
I don't understand the whole DCE reasoning. I mean - the cases show here and on mozilla's site are valid, but I'd like to know where in the world, aside from tests that aim to show browser maker's faults, does anyone actually write dead code?
As a developer I care for performance of my applications and optimize away what can be optimized - by using a profiler and analyzing compiler warnings. There are numerous books and articles on how to write good code.
This task should not be left to the JS engine - it only encourages writing sluggish and sloppy code hat does behave well only when certain conditions (read: browser version, JS engine, particular compile flag) are met. Instead there should be an interface set up that issues a warning: "Hey, this code does nothing. Consider removing it." in JS console or whatever JS devs use.
This whole JS seems to me that it could be improved - how about introducing some concepts from real programming languages, like typing, profiling, etc?