Tuesday, December 27, 2011

AWOAFY? (Are We Old And Fast Yet?, or, 9.0.1pre JM+TI available)

During the long death march to Firefox 4, Mozilla made much hay out of their Are We Fast Yet? site, a/k/a AWFY. AWFY was their daily dangling carrot while they worked on the first iteration of methodjit and offered regular feedback against the competition, and is still being used in the new type inference age. Well, JM+TI is here for PowerPC at last (that is, JaegerMonkey and type inference), and so is 9.0.1pre with new backends for your experimental pleasure. There are no other changes in this release and it is otherwise exactly the same as 9.0; it should fix all the known flaws in methodjit. (It does not include the fix Mozilla issued in Firefox 9.0.1 because I have received no relevant reports of crashes related to it, and it may impact performance, so there will not be a 9.0.1 unless I hear differently.)

So, with this release, I am now proud to bring you Are We Old And Fast Yet? where the first answer is yes and the second answer is "not enough." JM+TI now offers JavaScript speeds comparable to our old friend tracejit: on the quad G5, JM+TI (without tracejit) now matches the 1050ms on SunSpider that tracejit gets, and increases Dromaeo to 132 runs/sec. On our testing 1GHz G4/7450, Dromaeo rises to 38 runs/sec, and SunSpider drops slightly to 2750. (We're solving the missing square root problem for the present time by simply falling through to the JavaScript square root library routine. The G5 uses its native square root instruction, of course.)

This is already pretty darn good, but we can do better, and here is our goal for AWOAFY: quad G5 at Highest achieves less than 1000ms on SunSpider; 1GHz G4/7450 achieves less than 2500ms. These are totally doable; in fact, improvements in Firefox due to ship in the Fx11 timeframe may push these numbers down to target without us doing anything, but we're still going to shoot for low-hanging fruit optimizations in TenFourFox 10.

That brings us to what happens next. If Firefox 10 is indeed the ESR, as our Magic 8-ball predicts (it also predicted I would get a date with Scarlett Johansson, though), there are enough pieces of tracejit that it should still work and I think we should stick with tracejit as the default JIT for the duration of the 10 branch if so (with the option for JM+TI baked in for the adventurous): it's well tested, it's safe and it does well on our older hardware. I am waiting for beta 2 to be certified on mozilla-beta and once it is, we will begin the port. On deck for this release are some fixes from Ben and getting Tobias' fixed VMX text conversion routines back in action.

If Firefox 10 is not the ESR, then Fx10 will be the last tracejit release, and people will be forced to use JM+TI starting with Fx11. Sorry, this is Mozilla's call, not mine.

Either way, when we scramble to the ESR, the ESR will become our stable branch. Mozilla will backport security and stability fixes to the ESR which we will pick up, and unlike Mozilla, we will do other kinds of bugfixes to TenFourFox "ESR" that we deem appropriate. There will be no new features added, however. Most users will stay on this release.

For you, the rowdy, wild beta testers, there will still be beta releases, but not formal releases (because there won't be formal releases for awhile -- users will be kept on the ESR-based release). The situation we are trying to avoid is getting stuck on a release of Firefox that isn't getting security updates because we are unable to get the next one working. If, say, we get to Firefox 14 but can't make it to 15 -- and this is a real risk because Mozilla is already making noise about canning 10.5 support somewhere around Fx13, as we have previously discussed -- then we are marooning our users on a branch that will never get any fixes. By keeping later updates merely betas, most users are on a maintained branch and those of us out on the beta channel can just downgrade to the already existing release and live out our days in secure geriatric bliss in feature parity.

Assuming the ESR is 10, the next ESR would be Fx17. If we make it to Fx16, then we will do a regular beta release for Fx16, release Fx16, and go for 17. We can certainly backport security fixes from Fx17 to Fx16 if we fail at Fx17 and stay safe; the code is similar enough. If we don't make it to Fx16, then we can go on to feature parity against the ESR using the patches we've already done for later releases. So I feel pretty good about the future.

JM+TI is only transitional, however, because the future is Mozilla's new IonMonkey engine. This is months away from being functional, but I already looked at some of the code for the existing partially-functional backends and while much of our JM+TI work will transfer, there is a lot of work to do to get it working for PowerPC. Let's try to get as much wear out of the work we've already done.

Now, let's test AWOAFY. Download 9.0.1pre and go to about:config. Turn javascript.options.methodjit.chrome and .content to true, and turn javascript.options.tracejit.chrome and .content to false (yes, you are disabling tracejit; it is not compatible with type inference). Finally, set javascript.options.typeinference to true and restart the browser. Report your results! Remember to turn type inference off if you need to downgrade to 9.0, and turn methodjit off entirely if you downgrade to 9.0b1 or earlier.

Sunday, December 25, 2011

Our own Christmas present

After many days of non-stop debugging by Ben, Tobias and yours truly,

% ./jit_test.py --jitflags=mp ../../../obj-ff-dbg/dist/TenFourFoxDebug.app/Contents/MacOS/js # straight methodjit
[1775| 0|1775] 100% ===============================================>| 257.0s
PASSED ALL
% ./jit_test.py --jitflags=mnp ../../../obj-ff-dbg/dist/TenFourFoxDebug.app/Contents/MacOS/js # JM+TI
[1775| 0|1775] 100% ===============================================>| 270.0s
PASSED ALL


Now, how did Santa fit all that down the chimney? Again, this is an unoptimized JS, so ignore the timings.

The bugs that were repaired to get type inference working are systemic bugs, so they may actually fix the failure cases for straight methodjit. For G3/G4, we are simply going to prevent the optimizer from using a square root instruction for the time being and just use the JS math library routine (and later develop our own optimized assembly version that can be inlined). I'm going to do some more internal conformance testing this week and if this all checks out, hopefully we will have a 9.0.1pre for you to test by New Year's.

And keep Chris out of the eggnog.

Thursday, December 22, 2011

9.0.1 under review

I'm reviewing the single change in 9.0.1 (backout of bug 708572) to see if it applies to us, although it probably does. However, the relevant crash (bug 711794) seems to primarily affect 64-bit x86_64 and we are of course 32-bit PowerPC, and there is a definite performance impact to taking the backout. We don't support the offending toolbars implicated in the STRs in any case. Crash reports matching the signature would be strongly appreciated to allow me to make the call (please don't send other crash signatures unless you are positive they are related somehow). There is no security impact to this bug that I am aware of.

Tuesday, December 20, 2011

Is Fx10 the ESR?

I'm not sure if LegNeato made a Freudian slip, but comment 38 is very suspicious. It's also welcome news in case PPC JM+TI runs aground, because we could probably hack tracejit to work by itself in the ESR if we had to.

Two bits of bad news on methodjit. The first bit of bad news is that type inference requires the CPU to have a square root instruction, and only G5 does. We could emulate this on G3 and G4, but it would be expensive, of course. Assembly jockeys, here's your chance: come up with a routine in assembly to do PPC square root without a lookup table (you can use a couple constants if you like). It doesn't have to be fast because it's going to suck anyway; it just has to work. This routine might give you some ideas. Post your entries to issue 96; the winner gets beer.

The second bit of bad news is that we have some serious problem with how JavaScript stack frames are managed (not to be confused with the VMFrames we generate in methodjit), and it's not even in the code I wrote. I'm not sure if it's a compiler fart or not. This might be the explanation for some of the serious slowdowns on some sites, and it's possible the problem was there all along and it's just JM+TI that unmasks it. The problem crops up when nesting JS stack frames and if all else fails, I might be able to hack the interpreter to just turn TI off and drop to JM alone if the situation occurs. But that eliminates the entire advantage of JM+TI in the first place, and still isn't as fast as tracejit.

Life sucks. More later.

Monday, December 19, 2011

9.0 now release

9.0 is now in the release channel and available to users. As stated in the previous blog entry, methodjit is not on by default for the unwashed masses, just the regex compilation with tracejit which so far has proven to be very fast and safe.

So far there have been no reported crashes with methodjit, but I have received at least two reports of significant slowdowns on selected sites. We are tracking these in issue 119. Please only report sites there that are clearly and reproducibly being degraded by methodjit (i.e., you turn off methodjit and the problem goes away; you turn methodjit back on and the site drags back down again), not general slow issues or slowness from some other cause. It would also help to isolate a script as the specific cause using NoScript or similar tools in case we have to minimize a test case.

Type inference is still being difficult, but the MIPS port does not require anything extra of significance for it to work and MIPS is "big RISC" like us, so it's clearly something I've done wrong I haven't found yet. Right now I'm investigating stub calls, since they are by design non-ABI-compliant, and the extant code may be just clever enough to get it working in some places but not others. It is also possible that these two problems may be related.

I have also made the executive decision that we will not advance to 10 until we have both type inference and the basic methodjit working with no showstopper failures (i.e., no reproducible crashes or long hangs that are not reproducible in stock Firefox, and composite benchmarks that are not significantly worse than tracejit). We will issue interim 9 releases until then, because odds are good tracejit will be in serious disrepair in 10, even though it still exists. When I have these two issues nailed out, there will be a 9.0.1pre for you loyal beta users to try.

Saturday, December 17, 2011

9.0 RC available with secret sauce

9.0 RCs are now available. The RC fixes the missing favicons problem (this is actually a Mozilla bug, but they will not ship the fix until Fx10, for those of you using Firefox on an Intel Mac) and a glitch with a malfunctioning chrome script that causes weird behaviour on AMO and certain other OpenWebapps-integrated sites.

Oh, yeah, the secret sauce. It is generally not my policy to introduce new code in an RC, much to the annoyance of our contributors, and although in a strict sense the new code is also shipping as part of regex compilation (which was in the beta) the "sauce" is turned off as shipped. However, we're also in a bit of a time crunch. Fx10 is likely to have integration problems with tracejit at best and outright break it at worst, and losing tracejit with nothing to replace it specifically means a real punch in our gut.

So we really need to test our new JavaScript PowerPC methodjit now so that we can start working on any bugs and get type inference working (I'll discuss what that means in a moment), preferably for 10.4Fx 10. And that's what you're going to get to do with the "RC," because the RC has methodjit secretly embedded in it! Start the browser and go to about:config, and turn both javascript.options.methodjit.chrome and javascript.options.methodjit.content to true. Do not change any other values related to JavaScript, and do not turn type inference on (the browser will crash immediately if you do). Leave the tracejit on. Restart the browser to clear everything out. The browser will be a little slower to restore itself because it will now start compiling the chrome methods with methodjit as well.

Tracejit and methodjit attack JavaScript just-in-time compilation in two different ways. Our old friend tracejit watches the interpreter run code. If it sees something it determines is "hot," it turns on a tracer that translates JavaScript operations into an intermediate language called LIR and from there into PowerPC assembly language. This is very fast and the fastest way of running certain kinds of code, but branchy code paths cannot be built with tracejit because the execution runs in too many directions, and an unexpected change from the normal execution path means the tracer has to start a new one. So that's where methodjit comes in. If JavaScript determines (through profiling and various internal heuristics) that tracing will be unprofitable on a section of code, it can try simply compiling the entire JavaScript method en masse. This is slower than tracejit at some tasks because it may end up compiling code paths it may never execute (most importantly related to covering the gamut of implied types JavaScript makes possible -- read on), but it also allows certain kinds of optimizations that a tracer will never see because it only sees "one view" of the script rather than the entire bulk of code. The browser will pick which of them is most effective, caching its choice and the JITted code, and you will notice that as more code is in the cache the faster the browser gets.

Tracejit has fundamental differences from methodjit and Mozilla is proceeding in directions that tracejit is not compatible with, which is why it is being disabled in 10 and outright deleted from the tree in 11. This is bad for us, because tracejit executes certain kinds of code far faster than methodjit ever will. Mozilla's solution to methodjit's overhead is to introduce type inference to JavaScript. Remember that I mentioned part of the trouble with methodjit is compiling unnecessary code to cover the possible (or at least reasonable) permutations for JavaScript parameters and variables. If it could be determined what the most likely set of types were for an execution path, then code covering just those types could be built and the rest could fall through to the interpreter for a second chance while the methodjit revises its guess. The guess has to be good, because the penalty is to lose both the code compiled and to have to execute in the interpreter, a penalty tracejit hardly ever has to take because the types are already determined for it by the time the tracer gets enabled (and it doesn't have to junk the code path it already compiled, because it might use it again). This is where Mozilla is putting significant resources to beat Chrome V8 and Crankshaft, and Fx9 is the first Firefox where type inference is being exposed to the user by default.

Type inference makes drastic changes to the JavaScript engine, and as a result, JM+TI (that is, JaegerMonkey/methodjit with type inference) is incompatible with TM (tracejit), even though you can combine JM+TM without TI. But because type inference and other optimizations are part of the future IonMonkey project, tracejit is now old news. This is sad for us because our tracejit is very heavily optimized, but that wasn't my call, and Mozilla was kind enough to give us until Fx11 to get our backend shifted over. However, we don't support type inference yet -- I couldn't get it fully working in time. This is just as well since we should really test the core browser without it first.

So, shipping in this release is the Nitro macroassembler for PowerPC (which is an .h file with certain semi-atomic operations and their assembly-language equivalents), expanded for Mozilla's purposes, and a lower-level assembler that the macroassembler calls to do the translation. These are the pieces Ben diligently worked on the first draft of, and this version includes my completed draft with the bugs worked out. They are not as optimized as they could be, but they do work, and we can delay that a bit to get any other major issues out. Both YARR and methodjit use the macroassembler, YARR for regular expression compilation (which we do have enabled in 9), and methodjit for JavaScript. There is also a snippet of code called a "trampoline" which is a skeleton function prologue, epilogue and stub call library I wrote by hand in PowerPC assembly to interface with the JavaScript C++ interpreter, and the other pieces needed for JavaScript to understand OS X ABI stack frames and register allocation. Those of you watching our stack usage problem will now note that our methodjit stack frames are a fixed 128 bytes, overall smaller than tracejit, and our YARR stack frames are a fixed 32 plus any subpattern usage. We should start seeing smaller stack overhead when tracejit goes away, which is a consolation prize. The interested can see what our stack frames now look like in js/src/methodjit/MethodJIT.h and js/src/methodjit/TrampolinePPCOSX.s.

There is an effort underway to port the TenFourFox PowerPC-specific code to Linux. The VMX code Tobias wrote will translate pretty much directly, but the JIT compilers will not because they assume the OS X application binary interface, not the Linux ABI. Linux ABI uses different stack frame sizes, a different linkage area (the first few words of the stack frame), different volatile register designations and different parameter register allocation. Tracejit was not really written for anything else but OS X, but methodjit is being designed to be friendlier to our PPC brethren on other operating systems like Linux and should be particularly easy to port to AIX (and a tip of the hat to Andrew, who is running server-side JavaScript on big-iron POWER servers like our very own POWER6 here at Floodgap Orbiting HQ). I don't have any ETA on this and I am not personally involved with the project, but I have had contact with them and given them advice and suggestions. I'm sure they will post when they have early builds to play with. Please note that TenFourFox itself will always be for OS X; this effort would be better understood as part of a PowerPC-enhanced generic Firefox.

So, how are the numbers? My quad G5 doesn't change much on SunSpider (around 1050-1070ms for both TM and JM+TM), but Dromaeo in 9 goes from 114 to 122 runs/sec with JM+TM. The 1GHz G4 in 9 goes from 32 to 36 runs/sec and from 3300 to 2800ms in SunSpider. Overall, while not the dramatic change that tracejit was, it's still progress and I expect even more when we get type inference running; the project goal is still to get the quad G5's SunSpider time under one second and we're almost there. In the meantime I want you to bang on the browser hard, please -- we've got to get all the kinks out!

Some housekeeping. Firefox rapid release is developing a long tail of people not upgrading to later versions for a variety of reasons ranging from ignorance to add-on anxiety to update fatigue, which they have attempted to fix with the 3.6 to 8.0 "major update." The issue of the uninformed and shortly-to-be-marooned PowerPC Firefox 3.6 user notwithstanding, we have the same problem, made more acute by the termination of plugin support with TenFourFox 6. Nevertheless, I think it is bad form to have so many users on an unsupported branch with known security holes and I'm considering updating all the version snippets to remind users that TenFourFox 9 is available for them too and to please update to a supported version. They could of course ignore this nag as well, but at least we tried. Argue passionately for or against this idea in the comments.

One last note: do not downgrade to 9.0b1 with methodjit on -- make sure you turn it off before trying to re-run the beta for comparison, or the browser will immediately assert. In fact, you should probably do that for any previous version of TenFourFox, just to be safe.

On deck for 10 will be Tobias' fixed AltiVec text converters back in the lineup so he won't come over to my house with an axe ;), and some other additional minor optimizations, but type inference is the big kahuna and I may delay the beta until it is ready. As always the Secretary will disavow, I mean, the beta port will start when Mozilla certifies the first 10 beta. And this blog entry will self-destruct in five seconds because of the secret sauce. So you'd better read the release notes and download for your architecture now. Good luck, Jim.

Friday, December 16, 2011

Hello, methodjit

bruce:/home/spectre/src/bruce/mozilla-9b/js/src/jit-test/% ./jit_test.py --jitflags=mp,p ../../../obj-ff-dbg/dist/TenFourFoxDebug.app/Contents/MacOS/js

[3544| 0|3544] 100% ===============================================>| 369.4s

PASSED ALL


More about that when RCs come out. mozilla-release is now up to date, so 9 RC builds will commence later today, and if they pass conformance testing, up tonight or tomorrow. (Ignore the elapsed time as this was an unoptimized debug js.)

One other note. Some well-meaning individual submitted the QTE to Softpedia as a download. Please don't do that. It's an alpha, it's not finished, it has known bugs and we're not ready to support it yet. If it was you, please indicate to them that it was an error and retract it until we're ready with a beta. (In fact, you probably shouldn't submit it at all, since when it does hit beta we will just integrate it with TenFourFox itself, probably.) I appreciate your enthusiasm, but it was premature. Thank you :)