brave / brave-browser

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

Cache adblock DATs clientside #27161

Open antonok-edm opened 1 year ago

antonok-edm commented 1 year ago

We switched adblock lists to be served as plaintext components rather than serialized DATs in https://github.com/brave/brave-core/pull/15077. Loading adblock lists from plaintext is slightly slower than loading from a serialized DAT, although it leaves us the option of serializing them clientside to the newer uncompressed format which can be deserialized significantly faster. As per https://github.com/brave/brave-core/pull/15077:

Performance analysis

Benchmarking adblock-rust on my own computer shows a minor perf impact related to list parsing at startup, of an additional ~56ms or 32% regression for the entire set of default lists. Note that an additional change can allow adblock-rust to cache compiled DATs in uncompressed format after updates, resulting in a significant improvement to engine load time over the current master branch. I've left the caching for a followup to minimize the number of changes in this PR.

The benchmark results below show the engine load times for the current master configuration, the configuration as of this PR, and the configuration with caching, respectively (middle time value is average).

from_dat                 time:   [173.66 ms 174.88 ms 176.32 ms]
from_plaintext           time:   [228.08 ms 230.97 ms 233.52 ms]
from_uncompressed_dat    time:   [46.191 ms 46.777 ms 47.546 ms]

Brave should create a cached adblock DAT whenever lists are modified, and load this on startup to reduce load at browser-launch. Also, there is currently no code in place to prevent pages from loading before the adblock engines are ready, so this is important to help ads be caught on startup.

cuba commented 6 months ago

Note, this does not cover the iOS side of the work that needs to be done, the iOS side can be found here