Opened 17 months ago

Last modified 13 months ago

#7003 closed change

Implement alternative filter matching algorithm returning a boolean value — at Initial Version

Reported by: mjethani Assignee:
Priority: Unknown Milestone:
Module: Core Keywords:
Cc: sergz, greiner, sebastian, fhd Blocked By:
Blocking: Platform: Unknown / Cross platform
Ready: no Confidential: no
Tester: Unknown Verified working: no
Review URL(s):

https://codereview.adblockplus.org/29896562/
https://codereview.adblockplus.org/29932584/

Description

Background

The current filter matching algorithm in the matchesAnyInternal method of CombinedMatcher looks like this (pseudocode):

let blockingFilter = null;

for (let keyword of extractKeywords(location))
{
  let whitelistFilter = this.matchesAnyWhitelistFilter(keyword, location);
  if (whitelistFilter)
    return whitelistFilter;

  if (!blockingFilter)
    blockingFilter = this.matchesAnyBlockingFilter(keyword, location);
}

return blockingFilter;

The key insight here is:

  1. The function goes through each whitelist filter for each keyword, even if there is no blocking filter
  2. Most URLs don't have a blocking filter
  3. Any ad blocker is primarily interested in knowing whether or not a URL should be blocked, not whether or not the URL has any whitelist filters

An alternative version of this function would look like this (pseudocode):

let whitelistFilter = null;
let blockingFilter = null;

for (let keyword of extractKeywords(location))
{
  blockingFilter = this.matchesAnyBlockingFilter(keyword, location);
  if (blockingFilter)
    break;
}

if (blockingFilter)
{
  for (let keyword of extractKeywords(location))
  {
    whitelistFilter = this.matchesAnyWhitelistFilter(keyword, location);
    if (whitelistFilter)
      break;
  }
}

return whitelistFilter || blockingFilter;

To put it in words, if the URL has no blocking filters, it wouldn't look up any whitelist filter for the URL. In such a case (which is the most common case), it would simply return null.

The extension is not really interested in whitelist filters unless DevTools is open. It simply wants to know whether a URL should be blocked or not. Technically, a whitelist filter should be considered a "hit" only if it actually prevented a URL from being blocked.

[TBD: What to do]

What to change

[TBD]

Change History (0)

Note: See TracTickets for help on using tickets.