From bcaa1393629457c5551ba254b2acabc2dde47915 Mon Sep 17 00:00:00 2001 From: gorhill Date: Sat, 28 Jun 2014 11:40:26 -0400 Subject: [PATCH] hopefully better explanation --- js/abp-filters.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/js/abp-filters.js b/js/abp-filters.js index 4f6eeda04..db6b9a57b 100644 --- a/js/abp-filters.js +++ b/js/abp-filters.js @@ -1391,11 +1391,20 @@ FilterContainer.prototype.matchString = function(pageDetails, url, requestType, // or equivalent // allow = whitelisted || !blacklisted - // Since statistically a hit on a block filter is more likely than a hit - // on an allow filter, we test block filters first, and then if and only - // if there is a hit on a block filter do we test against allow filters. - // This helps performance compared to testing against both classes of - // filters in the same loop. + // Statistically, hits on a URL in order of likelihood: + // 1. No hit + // 2. Hit on a block filter + // 3. Hit on an allow filter + // + // High likelihood of "no hit" means to optimize we need to reduce as much + // as possible the number of filters to test. + // + // Then, because of the order of probabilities, we should test only + // block filters first, and test allow filters if and only if there is a + // hit on a block filter. Since there is a high likelihood of no hit, + // testing allow filter by default is likely wasted work, hence allow + // filters are tested *only* if there is a hit on a (unlikely) hit on a + // block filter. var pageDomain = pageDetails.pageDomain || ''; var party = requestHostname.slice(-pageDomain.length) === pageDomain ?