arantius/karma-blocker — pull request #6 by dtfinch (2013-10-02 03:04:44+00:00)
Title: Performance improvements

As I've been adding more regex rules, I've been noticing some hiccups during page load, so I tried to fix the two worst offenders identified by the Firefox profiler.

The big cpu user was the cloneObject() that it calls for every rulegroup check, to create a clean copy of rules to store results used the monitor display. Now it should only clone for results when the monitor window is open.

The next big cpu user was evalGroup(). I noticed it creates a new regexp object for every test, and a quick check on jsperf suggested reusing a regexp is about 4-5x faster in Firefox than recreating it each time. So I made it store the regexp it creates at parse time and reuse it.

In the process I noticed cloneObject() didn't handle regexes. I tried a simple instanceof check, but it doesn't appear to work right from extensions in Firefox, always returning false, though all the bug reports I could find were closed. I ended up settling for an uglier name check, which works, but I'm not proud of it.