BetterGA Is Dead (R.I.P)

As some of you may know, I developed a Firefox extension called BetterGA in 2008. Well today I have to tell you that the project is dead, and may it rest in peace.

[More]

Greasemonkey Optimization: Convert2RegExp

Over the last week I've been spending a great deal of time looking over the Greasemonkey and Webmonkey source code, both because I want to understand both code bases more, but also because I'm interested in Firefox extension internals in general. While looking through these two code bases I saw a common file which could be optimized. This file was the convert2RegExp.js file, which looks like it came from Adblock at some point, at least in part. In fact I saw a number of changes that I could try in order to speed up the function, so I decided to time them all.

Test Factors

Factor I: Check for /\.[^\.ld]*t[^\.td]*l[^\.lt]*d/ in pattern string character loop

The first thing I noticed was that the regular expression that checks the pattern string for a ".tld" string was being run on every pattern input, this seemed obviously bad to me since there was a loop prior to the regular expression which runs through the pattern string's characters, so why didn't that loop at least check for the ".tld" substring first? the check could be as simple as making sure all of the required letters exist in the string first, or make sure that the ".tld" substring, exactly, is in the pattern string, or what I found to be the best way was to make sure the regular expression /\.[^\.ld]*t[^\.td]*l[^\.lt]*d/ matched the pattern string via the character loop through the pattern string. The average cases and best cases will go much faster despite the fact that the latter case would be matching some pattern strings that following tld regular expression (that is already in convert2regexp) would not match, thus just adding work in this case, and making the worst possible case even slower.

Factor II: Cache tldStr and tldRegExp

The convert2RegExp( pattern ) function creates the tldRegExp and tldStr from literals on every execution! that might be a faster operation I thought, but I expected it to be slower than simply looking up the value of a variable when I timed it, and even though I haven't figured out how to test the memory consumption yet, I expect creating a large string from a string literal over and over again would increase the peak memory usage, and thus the garbage collector pause time as well. So, caching the tldStr and tldRegExp seemed like it would be a small win.

Factor III: Use array.push()/array.unshift() and array.join() instead of +=

From what I've read about Firefox 3.6 the += operator in loops is optimized to use a single StringBuffer, but there were a few += outside of the loop, and I figured some people will probably use versions of Firefox < 3.5 for some time to come still, and using an array there would certainly improve/decrease the peak memory usage. I didn't know what the affect on performance would be, but this change is commonly said to be the better approach for JavaScript in the past to present, mainly because of the memory issue. Furthermore, the more memory that is used, the more work there is for the garbage collector to deal with, which means your computer is even slower, and that time is hard to measure. I do know that a new feature to Firefox 3.6 is that the garbage collector frees the memory in a new thread, which means that older versions of Firefox did not, and that means that the chances of pauses were even greater. For more reading on these changes I am mentioning in Firefox 3.6 please read this article.

The Tests

Description

In order to test the factors listed above I knew I needed a number of different versions of the convert2RegExp function, but the other piece I needed was a collection of pattern strings to test. I made the different versions of convert2RegExp easily, but when it came to making the pattern set(s) to test I had to do some more thinking.

Test Pattern Sets

I may not have made the best choice, but I decided to use two pattern sets:

  1. Pattern Set 0: 3/50 patterns use the magic tld expression, 2/50 do not use the tld expression, but match /\.[^\.ld]*t[^\.td]*l[^\.lt]*d/
  2. Pattern Set 1: 2/50 patterns use the magic tld expression
In retrospect I think testing an even worse case might be advantages, although I don't suspect the tld expression is used very often. It's hard to say however, I would like to see an audit of userscripts.org, but even with that it'd hard to know what the average case is for all Greasemonkey users, even when you take the install counts from userscripts.org into account, although all of that perspective would be nice to have.

I am an avid user of Greasemonkey and I write quite a few userscripts, and I find that in practice that there are very few times when I would need to userscript to use the magic tld expression, so my feeling is that the ratio is probably closer to 1 tld pattern per 100 or more.

Test Pages/Versions

I decided to run my tests of the different factors listed above for FF3.5/FF3.6 on WinXP, OSX, and Ubuntu (only FF3.5). The test pages worth pointing out are:

  • Original
  • Alternate 3: test of only factor I
  • Alternate 5: test of only factor II
  • Alternate 6: test of factor II + minor change to return a value asap.
  • Alternate 11: test of factor I + II, uses array.unshift() and array.join(), and returns a value asap
  • Alternate 12: test of factor I + II, uses array.push() and array.join(), and returns a value asap
  • Alternate 13: test of factor I + II, and returns a value asap
  • Alternate 15: test using array.unshift() and array.join() as only change

Test Results

Here are the tests I ran and the results I record (the links are to published google docs spreadsheets, all values are in seconds):

AMD 2.21Ghz, DDR2, WindowsXP

Intel Duo 2.0Ghz, DDR3, Mac OSX

Intel Duo 2.0Ghz, DDR3, Windows XP

Intel 2.0Ghz, DDR, Ubuntu

Each test was using a version of convert2RegExp, on a set of 50 patterns, 2500 times.

Results

  • In all cases alternate 3 was faster than the original.
  • In all cases alternate 5 and 6 were faster than the original.
  • In all cases alternate 6 seemed to be slightly faster than 5.
  • In all cases alternate 15 is much faster than the original for FF3.6, and slightly slower for FF3.5.
  • For FF3.5 alternate 13 > alternate 12 ~= original ~> alternate 11
  • For FF3.6 alternate 11 > alternate 13 > alternate 12 > original.
Although for FF3.5 we know that alternate 13 is a bad choice because it uses the += operator which result in O(N^2) characters copied, so we can't use that in my opinion. The final choice has to be between alternate 11 and alternate 12.

This is where I need your help, I have no idea why using array.unshift() is so much faster in Firefox 3.6, and taken that it is, and that the majority of Greasemonkey users will be using the latest version of Firefox, should we use array.unshift() and not array.push()?

Tweet Me!

Some Firefox About:Config Performance Suggestions

After reading "JavaScript speedups in Firefox 3.6" by Alix Franquet, which mentions the JIT for browser UI JavaScript about:config variable named javascript.options.jit.chrome, which was available in Firefox 3.5 and I didn't know it, I finally decided to review all of the Firefox about:config variables and find out what they all were. After I did so I found quite a few settings that if changed from their default settings would make Firefox even faster. These are the settings I want to go over in this article.

To start off with, I would recommend that you install Firefox 3.6 RC2 or higher, because if you read the article I mention above, then you will know why Firefox 3.6 is so much faster than 3.5 is.

About:Config Settings

I'm not going to list every about:config setting, only the ones that I think if changed should improve Firefox's performance.

[More]

Goo.gl Now Open For General Use

Screen shot of Goo.gl fixed up with the userscript mentioned below

Three days ago Google announced it's release of Goo.gl a url shortener which is more reliable and trust worthy (to a user) than other services such as tinyurl.com, tr.im, bit.ly, etc.

Now I think all web publishers should maintain their own url shortener which only they can create urls for and control, for example I bought the domain evold.ca, and use the subdomain r.evold.ca as my url shortener. I primarily use this domain to shorten urls to my other domains, like erikvold.com, but I can and do occasionally use it to create short urls for domains that are not mine. As a user, when I see a blog post that I want to share, I first check if the publisher has published a short url for the page, which any smart web publisher does, but for the other web publishers (the majority atm) I have to create a short url, which I can now use Goo.gl to do.

The problem is that Goo.gl does not allow users to use it to shorten links directly. Currently, the Google URL Shortener is only officially available via the Google Toolbar and FeedBurner.

Well, I noticed that this problem was solved yesterday by a Google Chrome extension called goo.gl shortener. Amit Agarwal drew my attention to this extension in a blog post he wrote yesterday, where he pointed out the important javascript parts needed to create goo.gl short urls. So I took this information and opened Goo.gl up with a userscript, a ubiquity command, and a jetpack to help everyone create short urls with Goo.gl, check them out!

A Jetpack: Java Settings

This Jetpack is meant to help Firefox users quickly enable and disable Java or JavaScript, and it is my third entry for the Jetpack 50-line Code Challenge.

Java Settings Jetpack

About

This Jetpack will add a "Enable Javascript" and "Enable Java" menu items to your "Tools" menu for quick access to these settings.

Screen Shot

How To Install

  1. Get Firefox here.
  2. Get Jetpack here
  3. Get the "Java Settings" Jetpack here

[More]

A Jetpack: Firefox 'Restart' Menu Item

I wrote this Jetpack as another entry for the Jetpack 50-line Code Challenge, it is simply a 'Restart' menu item for Firefox's 'File' menu.

When I was trying to come up with ideas I starting thinking about replacing a number of Firefox extensions I currently use with a lightweight Jetpack. So I instantly thought about Quick Restart, by Juan Carlos Avila B, which I have used a lot in the past, but it had a bunch of extra data packaged with it that I didn't want such as localization (albeit I'm sure this is something others want), xul, css, and images files.

I've used Quick Restart for some time now, and still think it is a great addon, but I'm pleased to say that there is a Jetpack option available now.

Firefox 'Restart' Jetpack

About

This Jetpack is using source lifted from the Ubiquity Firefox extension's built-in 'restart' command.

Screen Shot

Screen shot of the 'Restart' menu item in Firefox's 'File' menu

How To Install

  1. Get Firefox here.
  2. Get Jetpack here
  3. Get the "Firefox 'Restart' Menu Item" Jetpack here

[More]

A Jetpack: Tweet This!

I wrote my first entry for the Jetpack 50-line Code Challenge a few weeks ago and I would like to share it with you now. The Jetpack is called Tweet This!, and it is meant to help you quickly tweet about a page you are viewing in Firefox with the document's published short url, if it is defined (otherwise tr.im is used).

Tweet This!

Details

The Tweet This! Jetpack adds a 'Tweet This!' menu item to Firefox's 'Bookmarks' menu and context menu, which when used, will allow the user to Tweet about the page they are on. A user can select some text on the page, or else the page's title will be used for some text in the tweet, and then the Jetpack will first check if the text + long url is less than 140 characters long, and just use the long url if so, but otherwise it will use my Get Short URL service (hosted by Google App Engine) to find the shortest url for the page, which is published by the page, and if one has not been published which is smaller than a length you can change in settings, but is by default 35. If the shortest url found is not shorter than the setting length specified then the tr.im service is used to create a short url for the page.

After the Jetpack has a short url for the page, and some text to tweet about it, it will finally trim the text so that the tweet is equal to 140 chars if necessary, then send the tweet, and notify you with the tweet if it has been sent (also the username that it was sent from is displayed).

Notes

  • If you do not see a notification, then an error occurred, and no tweet was sent, so it will be safe to try again, just make sure you wait about a minute before trying again (don't be too hasty). An error would only occur if the Tr.im or Twitter servers return an error.
  • The jetpack settings are pretty basic, and while they provide a range type they do not show the range to the user, or the value the user has selected in the range. Hopefully this will be changed in short time, but until then I'll just let you know here the Max URL Length range is from 20 to 100.

[More]

A Jetpack: Google Web History

This Jetpack adds a "Show Google Web History" menu item to your Firefox "History" menu.

Get it at:

A Jetpack: Greasemonkey Context Menu

This Jetpack will add the Greasemonkey menu commands to your context menu.

Screen Shot

Get it at:

A Jetpack: Twitter Message Notifier

This is a simple Jetpack Twitter notifier, which checks for new mentions or direct messages for your account and notifies you of them.

The Jetpack loops through tweets to notify you about every 7.5 seconds, until it has no more remaining, then waits 5mins and checks for more DMs or mentions from your Twitter account.

Get it at:

More Entries

© Erik Vold 2007-2010. Contact Erik Vold. Top ^