An optimized object for matching against match patterns. A MatchPatternSet can provide
a significant performance improvement in comparison to RegExps, in some instances
greater than 100x. A MatchPatternSet can also be exported to an object that uses only
built-in types, so it can be persisted or passed to content scripts in extension storage.
There are several key optimizations in MatchPatternSet:
- URLs are parsed with the
URL class, which has native implementation.
- Match patterns are indexed by hostname in a hash map. Lookups are much faster than
iteratively advancing and backtracking through a complex regular expression, which
is how domain matching currently occurs with the
Irregexp regular expression
engine in Firefox and Chrome.
- Match patterns with identical scheme, subdomain matching, and host (i.e., that
differ only in path) are combined.
- The only remaining use of regular expressions is in path matching, where expressions
can be (relatively) uncomplicated.
Future performance improvements could include:
- Replacing the path matching implementation to eliminate regular expressions entirely.
- Replacing the match pattern index, such as by implementing a trie.