Tuesday, July 2, 2013

Useful tips: making threads out of Tiger can be difficult (plus: Tenfourbird is awesome)

Because it has all these claws and sharp bits and it doesn't like being made into thread I have been displeased with the performance thus far of 22 after a while using it regularly (recall that I was on vacation in the beautiful Pacific Northwest and my iBook G4 usually runs 17 so that I can make sure the stable branch is still working well), and I think I finally know why. It's a manifestation, yet again, of Tiger's comparatively poor multithreading performance compared to Leopard and later kernels, the crux of which is issue 193 (and should hopefully be solved once and for all if I can get jemalloc functioning properly, which is issue 218). Unfortunately, the performance issues appear to be because of Mozilla's well-intentioned attempts to move stuff off the main thread, and of the local test systems the multi-processor Power Macs -- the ones you'd think would benefit most -- actually do tremendously worse with this approach in 10.4.

Permit me to demonstrate. If you're on a single processor Mac, going to Butterfly Labs (the reliable test case for this problem, though I'm sure there are others) is sluggish and beachballs a bit, though it eventually loads. My iMac G4 grinds into it after around 30 seconds, which is lousy, but bearable. Now do it on a multi processor Mac. On my 10.4 quad G5, it takes minutes despite having four times the cores, four times the L2 cache and 2.5 times the clock speed, even with processor performance set to Highest, during which the browser is unresponsive for long periods of time. That, to express it gently, sucks. After some exhaustive debugging I am fully convinced that this too is almost entirely due to inefficiencies in the Tiger kernel's implementation of pthreads. The processors just trip over each other trying to stay synced and the threads get starved for resources.

I am told that issue 193 does not affect 10.5 nearly as badly if at all as it does 10.4, so I've made a speculative fix to NSPR and JavaScript tracked as issue 231. Until I can get jemalloc to work correctly and solve the whole problem, the simplest stopgap solution seems to be to make TenFourFox believe there is only one processor on 10.4 systems, regardless of how many it actually has, which causes the browser not to attempt to spin things into multiple threads. (The patch checks Gestalt() to see if it it's on 10.4; if it isn't, it runs the normal processor detection code.) I'm typing this in such a build on the G5 and the weird intermittent stops and seizes I also observed with 22 are now nearly undetectable, even with the processors throttled to Reduced mode. 10.5 users, please try the reliable test site above on single and multi-processor Power Macs if you have them available. The difference should be extreme on the multi-processor Power Mac if 10.5 is affected by this also and if it is, then we just make it detect only one processor on any Power Mac until we can work around the poor kernel performance later. (jemalloc is number two on my priority list, behind, of course, BaselineCompiler/IonMonkey.) Either way, one form or another of this fix will appear in 22.0.1, which is the interim release to replace Fx23 while I work on Fx24. It won't help sites much that were already bad in previous versions, but it will definitely fix the accumulated regressions.

Other things. Now that Google has made Google Groups slow and hard to navigate, which I used to use for reading Mozilla newsgroups (though I guess that's better than what they did to Google Reader), I finally have an excuse to try Tenfourbird. Normally I read Usenet and E-mail from a shell prompt, but I decided to use Tenfourbird and talk to news.mozilla.org directly to see how well it works, and to keep those groups separate from my regular .newsrc file. And, well, wow. It's quick and fast, and seems pretty much bug-free. I am delighted to see that our anonymous builder in the land of the rising sun has kept pace with us, and I hope he makes the jump to 24 when we do. ありがとうございました。

13 comments:

  1. "I am told that issue 193 does not affect 10.5 nearly as badly if at all as it does 10.4"

    ++++++++++++++++++++++++++++

    Clicked the link for butterfly Labs on my 1.67 GHz G4 Powerbook running Leopard and 22. No problem as the page loaded very quickly.

    ReplyDelete
  2. I don't have a multiprocessor Mac to test this with. On the G4 PB (1.33 GHz, 10.5), it loads in about 30 seconds, and on the iBook G3 (800 MHz, 10.4) it takes about 2 mins. With JS disabled it loads almost instantly.

    However I've got an OT tip for speeding up TFF: Adblock Plus is used by many, and it has become bloatware over the last months after it was sold to Eyeo and is now generating money with "acceptable ads". For me, it's the one and only add-on that really noticeably impacts performance. I installed Adblock Edge instead (a fork of the older 2.1.x code), and voila! Using the exact same settings and filter subscriptions, speed is restored to what it used to be over a year ago, before Adblock Plus started correcting typos and whatnot.

    ReplyDelete
    Replies
    1. Well, I will say this: on the iMac G4, I decided to see what difference ABE made over ABP. It reduces the load time on that page to 10 seconds instead of 30. That's impressive (and says something about how much bloat is in ABP). Thanks for making me aware of it -- it seems more functional than ABL, which is necessarily more limited. I'm going to use it regularly and see if it's worth changing our recommendation from ABP to ABE.

      That said, I don't want to turn TenFourFox into Classilla -- we *should* be able to run JS on most sites, and improving multithreading performance will be key.

      I've toyed with making a post on popular and performant extensions for TenFourFox (the set I use, and then the top five suggestions more or less organized by genre posted by users). If people like, post suggestions in the comments for this post and I'll collate them.

      Delete
  3. I recommend UnPlug. I use it to find link to videos in webpages, that I can then open in external players. As its name suggests, it has been designed to work without plugins, so it' s perfect for TFF. It's launched only on request, so it is very lightweight and doesn't increase loading times. Plus it has a clean user interface, and it works with embedded videos. As always if you are using NoScript you will have to temporarily allow videos on the page.

    https://addons.mozilla.org/it/firefox/addon/unplug/

    As for adblockers I'm using Glimmer Blocker on 10.5, which I find lightweight and powerful. It needs Java though, so I'm considering switching to Privoxy (and that should work on 10.4 and Linux too). Have you got any experience with it?

    ReplyDelete
    Replies
    1. I haven't used Privoxy, no. I hear good things about it though.

      Delete
  4. I'm here to express my appreciation for everyones effort in maintaining the usefulness of older Macs. I don't have the money to buy a new computer, but asking people in my community nicely and performing a few simple repairs has provided me with several computers for free- or nearly so.

    Thank You!

    ReplyDelete
  5. For a very lightweight "adblocker" you could use https://addons.mozilla.org/en-US/firefox/addon/adblockingfiltersetp/. I did some sunspider tests and it doesn't seem to have much, if any, impact on JS speed, while Adblock Edge still reduces speed by about 20%. Of course, this is just a static filterset in a CSS (sort of like Camino does its adblocking), with no customization. It does catch the majority of ads, but not all of them, and I haven't seen any false positives yet. Also, it reduces RAM usage considerably.

    ReplyDelete
    Replies
    1. The comments don't seem to give it good reviews, though, but I certainly like the static approach. Maybe someone(tm) could adapt the Camino adblocker itself. The CSS is within the application package. It might be worth implementing when we drop source parity.

      Delete
    2. The most lightweight ad blocker is a well prepared /private/etc/hosts file, you can download one here. It blocks majority of ads without using any RAM, just by redirecting to 127.0.0.1 (or 0.0.0.0, or 255.255.255.255)

      Delete
  6. I noticed a minor UI oddity while making the 22 German test version: If the About dialog is shown, clicking "Check for updates…" does nothing, i.e. the Update windows doesn't appear. This might be weird for people who use the About dialog to check which version they're on, and then right away want to get the latest update without closing the About window first.

    ReplyDelete
    Replies
    1. Yes, I can confirm that. Looks like this has been there probably since the beginning (at least as far back as 17, but that code has not appreciably changed since Firefox 5). I'll have to see how easy it is to fix.

      Delete
  7. A bump here, but one way to speed up Google Groups is to use the addon Override User Agent. You can change the user agent on a per-site basis, so I made it so that Groups thought that my iBook is an iPhone.

    ReplyDelete

Due to an increased frequency of spam, comments are now subject to moderation.