Skip to content

Commit b265f26

Browse files
committed
Coallesce origin hit filters into their own bucket
Performance-related work. There is a fair number of filters which can't be tokenized in uBO's own filter lists. Majority of those filters also declare a `domain=` option, examples: *$script,redirect-rule=noopjs,domain=... *$script,3p,domain=...,denyallow=... *$frame,3p,domain=... Such filters can be found in uBO's asset viewer using the following search expression: /^\*?\$[^\n]*?domain=/ Some filter buckets will contain many of those filters, for instance one of the bucket holding untokenizable `redirect=` filters has over 170 entries, which must be all visited when collating all matching `redirect=` filters. When a bucket contains many such filters, I found that it's worth to extract all the non-negated hostname values from `domain=` options into a single hntrie and perform a pre-test at match() time to find out whether the current origin of a network request matches any one of the collected hostnames, so as to avoid iterating through all the filters. Since there is rarely a match() for vast majority of network requests with `domain=` option, this pre-test saves a good amount of work, and this is measurable with the built-in benchmark.
1 parent fe2c4a4 commit b265f26

File tree

2 files changed

+226
-92
lines changed

2 files changed

+226
-92
lines changed

src/js/background.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ const µBlock = (( ) => { // jshint ignore:line
139139

140140
// Read-only
141141
systemSettings: {
142-
compiledMagic: 31, // Increase when compiled format changes
143-
selfieMagic: 31, // Increase when selfie format changes
142+
compiledMagic: 32, // Increase when compiled format changes
143+
selfieMagic: 32, // Increase when selfie format changes
144144
},
145145

146146
// https://github.com/uBlockOrigin/uBlock-issues/issues/759#issuecomment-546654501

0 commit comments

Comments
 (0)