brave / brave-browser

Brave browser for Android, iOS, Linux, macOS, Windows.
https://brave.com
Mozilla Public License 2.0
17.94k stars 2.35k forks source link

Measure performance of alternative regex engines for adblock #28182

Open atuchin-m opened 1 year ago

atuchin-m commented 1 year ago

Currently we use rust Regex to match adblock regular expression. As discovered in https://github.com/brave/brave-browser/issues/26892, it consumes a lot of memory.

In chromium we a few alternative engines:

  1. javascript Regex: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
  2. declarativeNetRequest: https://developer.chrome.com/docs/extensions/reference/declarativeNetRequest/#type-RegexOptions
  3. UrlMatcher: https://source.chromium.org/chromium/chromium/src/+/main:components/url_matcher/url_matcher.h;l=119

The task is to compare the performance/memory consumption of these engine for typical adblock regular expressions.

Also changing the regex engine to C++ implementation implies moving adblock engine to sandbox process (the rule of 2)

bridiver commented 1 year ago

@atuchin-m shouldn't we also look at why it consumes so much memory? Have you reported this issue to rust? Or is there another rust regex implementation that is better?