I’ve been having performance problems with my Firefox (2) for months. Opening lots of tabs at once, or even a particularly large page, would cause the browser to freeze for several seconds. I finally got around to tracking this down, and it turned out to be a couple of GreaseMonkey scripts.
The postcode linkifier puts together an XPath expression:
var xpath = "//text()[(parent::" + allowedParents.join(" or parent::") + ")]";
where allowedParents is an array of 50 tag names. It then evaluates it, and applies a complicated postcode regexp (although not quite the full thing):
const pcRegex = /\b[A-PR-UWYZ][A-HK-Y0-9][A-HJKSTUW0-9]?[ABEHMNPRVWXY0-9]?
to all the text. I can imagine that this is inefficient, although I wouldn’t like to guess at which part takes the lion’s share.
The Bible refalizer uses simpler XPath:
textNodes = document.evaluate('//text()', document, null,
but a much more complicated regexp involving various abbreviations of the names of the 66 books of the Bible.
So the question is: is there a way of providing this type of full-text search and modify function which has acceptable performance? Does the Firefox platform need to provide more help with this particular use case? It seems to me that it might be quite common.