[RFC] Adblock request-matching: ~3.9x faster matching (patch attached)

Rob Rich robrich999 at yahoo.com
Fri Aug 14 02:05:32 BST 2026


Hello,
I've been profiling Falkon's adblock network matching and ended up with threesmall, independent changes to src/lib/adblock that I'd like to share in casethey're useful upstream. This is not a PR - just findings and a patch, with nomaintenance obligation on my part.
Scope first, so expectations are clear: these changes speed up the adblockmatching itself, which runs in the browser process. Overall page load isdominated by QtWebEngine (Chromium), which these changes don't touch, so theend-to-end effect on typical pages is modest. The numbers below describe theadblock matching phase and the browser-side portion of the load.
Results. The matching cost dropped ~3.9x (283-289 ms -> 72.5 ms of browser-sideload time on a deliberately ad-heavy synthetic page: 115 requests, 80 blocked,the four common subscriptions loaded). Instruction count for the workload fell~6.5x (31.3B -> 4.8B instructions in the main process), and adblock matchingwent from ~58% of browser-process samples to a flat profile. Against a realbinary, the distro build of falkon 25.12.3 measured 240.8 ms vs 66.9 ms for theoptimized build on the same workload, again reflecting the browser-sidematching time, not the full wall-clock page load. Blocking behavior isunchanged: blocked=80/80 on every run, adblocktest 25/25, and a differentialtest on regexp/ends rules matches the baseline exactly.
The three changes:

  1. Pre-fold rule match strings at parse time and match case-sensitively     against the already-lowercased request URL/domain, removing the repeated     Qt Unicode case-conversion from the hot path.  2. Index the ~53.7K '||domain^' rules by the pattern's last two labels, so a     request only scans its own domain bucket.  3. Index ends and regexp rules by pattern last-char / first bigram, so only     buckets relevant to the request are checked.
These are algorithmic changes (fewer string operations, not faster ones), sothe win is independent of -march and should hold on distro-neutral builds.
The attached RFC has the full methodology, per-step numbers, memory/complexitycosts, and reproduction instructions; the patch applies cleanly againstmaster (git format-patch variant included for git am).
The bulk of the work done here was done via many interative prompts and runs
with OpenCode using Qwen3.6 35B A3B, so consider this a contribution to the
discussion if the project finds any of this worthwhile for further research and/or
integration.
Thanks for your time,

--Robert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/falkon/attachments/20260814/81078220/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Optimize-adblock-network-matching-pre-fold-domain-en.patch
Type: text/x-patch
Size: 17788 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/falkon/attachments/20260814/81078220/attachment-0002.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: falkon-adblock-perf.patch
Type: text/x-patch
Size: 16114 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/falkon/attachments/20260814/81078220/attachment-0003.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: RFC-adblock-perf.md
Type: text/markdown
Size: 9324 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/falkon/attachments/20260814/81078220/attachment-0001.md>


More information about the Falkon mailing list