-
Notifications
You must be signed in to change notification settings - Fork 141
Flat buffers #416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Flat buffers #416
Conversation
e515e7b
to
2dca480
Compare
…ource_assembler.rs
…oved direct deps on NetworkFilter from RegexManager and matchers.
…k.rs to network_matchers.rs
Removed AnyOr trait.
…chers for flat filters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rust Benchmark
Benchmark suite | Current: a2a8f5a | Previous: 7919bdd | Ratio |
---|---|---|---|
rule-match-browserlike/brave-list |
1917794686 ns/iter (± 20902834 ) |
1745226241 ns/iter (± 10688991 ) |
1.10 |
rule-match-first-request/brave-list |
1052414 ns/iter (± 13996 ) |
1003256 ns/iter (± 7610 ) |
1.05 |
blocker_new/brave-list |
159015429 ns/iter (± 3655404 ) |
210108247 ns/iter (± 7007989 ) |
0.76 |
memory-usage/brave-list-initial |
21457739 ns/iter (± 3 ) |
41409969 ns/iter (± 3 ) |
0.52 |
memory-usage/brave-list-after-1000-requests |
24064706 ns/iter (± 3 ) |
44005995 ns/iter (± 3 ) |
0.55 |
This comment was automatically generated by workflow using github-action-benchmark.
Would've liked to see capnproto instead of flatbuffers, but still this is good, great work 👍 |
I want to try it after the flatbuffers. |
This pull request marks the first stage of optimizing the ad blocker’s memory usage. It introduces the ability to store network request blocking rules in
FlatBuffers
. At this stage, memory consumption is reduced by half (a 2x improvement) with the same lookup performance. Future enhancements will focus on optimizations like eliminatingHashMap
s, aiming to achieve a 3x overall improvement in memory efficiency.abstract_network.rs
. This reduces the amount of code in thenetwork.rs
file.RegexManager
. This is preparation for breaking the direct dependency ofRegexManager
onNetworkFilter
.network_matchers.rs
. Also in this commit, loops in the macthing functions have also been replaced with any and all. Additionally, a traitAnyOrExt
was introduced, adding anany_or
method to iterators. However, this turned out to be an good solution, and in subsequent commits, it was removed in favor of using early returns.url_lower_cased
field has been added to thestruct Request
. This reduces the number of memory allocations during filter lookup and speeds up the matching. Astruct Tokens
has been introduced, and tokens are now calculated once and stored as a field in thestruct Request
. This simplifies and speeds up the code. A methodcheckable_tokens_iter
has been added toRequest
that returns the sequence of tokens that need to be checked. Theobject-pooling
feature has been removed.struct NetworkFilterList
has been moved fromblocker.rs
to a separate file,network_filter_list.rs
. Corresponding tests have been relocated totests/unit/network_filter_list.rs
include
andexclude
domains now stored asu16
indices instead ofu64
hashes in a separate sorted arrayunique_domains_hashes
FlatNetworkFilter
intoBlocker
. Added aNetworkFilterMaskHelper trait
, into which the boolean getters have been moved.check
,check_all
, andfilter_exists
. Now, there is a single loop iterates over sequence fromRequest::checkable_tokens_iter()
.Blocker
has been renamed toGenericBlocker<NetworkFilterListType>
, which may depends on the type of list:NetworkFilterList
orFlatNetworkFilterList
. Added an implementation forFlatNetworkFilterList
.FlatNetworkFilterList
to ensure that the results match in terms of speed and filter lookups with the implementation based onNetworkFilterList
.FlatNetworkFilterList
. Rules are optimized during creation. NowFlatNetworkFilterList
doesn't depend onNetworkFilterList
.