Opened on 11/02/2018 at 12:20:39 AM
Closed on 12/12/2018 at 05:36:52 PM
Last modified on 02/07/2019 at 03:23:53 AM
#7089 closed change (fixed)
Use type-specific maps for matching non-default types
Reported by: | mjethani | Assignee: | mjethani |
---|---|---|---|
Priority: | P2 | Milestone: | |
Module: | Core | Keywords: | |
Cc: | Blocked By: | ||
Blocking: | #7000 | Platform: | Unknown / Cross platform |
Ready: | no | Confidential: | no |
Tester: | Unknown | Verified working: | no |
Review URL(s): |
Description (last modified by mjethani)
Background
Most filters apply to at least one default content type like $script, $image, $stylesheet, and so on, but only some filters apply to non-default types like $csp, $elemhide, $genericblock, etc. Yet the non-default types are queried for each document.
Right now filters in the matcher are divided into blacklist (blocking) and whitelist. After #6994, they are further divided into "simple" (location only) and "complex". A filter with a non-default type like $csp goes in the "complex" map.
Looking at the data structures in the matcher with EasyList+AA, there are ~6,200 whitelist filters in the "complex" category, but only ~900 of these are $elemhide filters. Similarly, there are ~18,500 "complex" blocking filters, but of these only ~90 are $csp filters. If there were separate type-specific maps for $csp, $elemhide, and so on, matching would be a lot faster. In most cases, especially for $csp, matching would terminate immediately since no filters would be found for the keywords in the URL.
After applying the patch, I found filter matching for whitelisting and CSP to be faster by roughly 40-45% with a URL containing three known keywords.
What to change
See patch.
Hints for testers
Test blocking and whitelisting filters thoroughly.
Specifically make sure that $csp, $popup, $document, $genericblock, $elemhide, and $generichide work as expected.
Here are some examples:
- If there's a filter ^test.html^$csp=script-src 'none' and the page test.html contains an inline <script> element, the script should not be executed
- If there are two filters ##.foo and ^test.html^$elemhide, the element <div class="foo">X</div> in test.html should not be hidden
- If there are two filters /foo^ and ^test.html^$document, a request for https://example.com/foo from test.html should not be blocked
Attachments (0)
Change History (8)
comment:2 Changed on 11/02/2018 at 12:26:17 AM by mjethani
- Blocking 7000 added
comment:3 Changed on 11/02/2018 at 08:31:20 PM by mjethani
- Status changed from new to reviewing
comment:4 Changed on 12/12/2018 at 12:46:25 AM by abpbot
comment:7 Changed on 12/12/2018 at 05:36:52 PM by mjethani
- Description modified (diff)
- Resolution set to fixed
- Status changed from reviewing to closed
comment:8 Changed on 02/07/2019 at 03:23:53 AM by abpbot
A commit referencing this issue has landed:
Issue 7089 - Match filters by type for non-default types
A commit referencing this issue has landed:
Issue 7089 - Match filters by type for non-default types