Added parser for $to option in NetworkFilter.#701
Conversation
|
[puLL-Merge] - brave/adblock-rust@701 DescriptionAdds parsing/storage for Possible Issues
Changessrc/data_format/mod.rs
src/filters/abstract_network.rs
src/filters/network.rs
src/filters/fb_network_builder.rs
src/flatbuffers/fb_network_filter.fbs + generated.rs
tests/unit/
Notes
sequenceDiagram
participant Src as filter line "$to=..."
participant AN as abstract_network::parse_filter_options
participant NF as NetworkFilter::parse
participant FB as NetworkRulesBuilder::add
participant Flat as fb_network_builder
Src->>AN: parse options
AN->>AN: parse_pipe_delimited_domains(value)
AN-->>NF: NetworkFilterOption::To(domains)
NF->>NF: hash_pipe_delimited_domains -> opt_to_domains / opt_to_not_domains
NF-->>FB: NetworkFilter{ opt_to_* set }
FB->>FB: has_to_option()?
alt has $to
FB-->>FB: early return (not indexed for matching)
else no $to
FB->>Flat: serialize + index
end
FB->>Flat: serialize opt_to_* fields (storage only)
|
There was a problem hiding this comment.
Pull request overview
This PR adds parsing and serialization support for the $to= option in network filters, while aiming to keep runtime matching behavior unchanged by not applying $to constraints during request evaluation.
Changes:
- Added
$to=parsing (pipe-delimited domain list with~negation) and stored the parsed data onNetworkFilter. - Extended the FlatBuffers schema/data format to persist
$todomain restrictions and bumpedADBLOCK_RUST_DAT_VERSION. - Added/updated unit tests and adjusted engine serialization hash expectations to reflect the new data format.
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/filters/network.rs | Adds unit tests asserting $to= is parsed into opt_to_domains / opt_to_not_domains. |
| tests/unit/filters/network_matchers.rs | Adds tests asserting $to-containing filters do not affect matching behavior. |
| tests/unit/filters/abstract_network.rs | New unit tests for pipe-delimited domain parsing helper. |
| tests/unit/engine.rs | Updates expected serialization hashes and network filter counts for the new format. |
| src/flatbuffers/fb_network_filter.fbs | Adds opt_to_domains / opt_to_not_domains fields to the NetworkFilter FlatBuffer table. |
| src/flatbuffers/fb_network_filter_generated.rs | Regenerates FlatBuffers bindings to include the new fields and other generator output changes. |
| src/filters/network.rs | Stores $to domain restrictions on NetworkFilter, wires parsing, and includes them in filter ID computation. |
| src/filters/fb_network_builder.rs | Serializes $to domain restrictions, and currently skips inserting $to filters into the engine. |
| src/filters/abstract_network.rs | Introduces parse_pipe_delimited_domains and uses it for domain/from and new to options; wires unit tests. |
| src/data_format/mod.rs | Bumps the persisted data format version from 5 to 6. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Rust Benchmark
Details
| Benchmark suite | Current: 3f916d7 | Previous: bd2f117 | Ratio |
|---|---|---|---|
rule-match-browserlike/brave-list |
2242670735 ns/iter (± 17711909) |
2381054868 ns/iter (± 34045922) |
0.94 |
rule-match-first-request/brave-list |
1363603 ns/iter (± 89562) |
1472017 ns/iter (± 27538) |
0.93 |
blocker_new/brave-list |
114674686 ns/iter (± 2148085) |
116855936 ns/iter (± 843156) |
0.98 |
blocker_new/brave-list-deserialize |
31095429 ns/iter (± 105372) |
33093630 ns/iter (± 1471291) |
0.94 |
memory-usage-final/brave-list-initial |
9560898 B/iter (± 0) |
9560762 B/iter (± 0) |
1.00 |
memory-usage-final/brave-list-1000-requests |
3157476 B/iter (± 0) |
3157476 B/iter (± 0) |
1 |
memory-usage-max/brave-list-initial/max |
32069586 B/iter (± 0) |
32069450 B/iter (± 0) |
1.00 |
memory-usage-alloc-count/brave-list-initial/alloc-count |
284056 allocs/iter (± 0) |
282954 allocs/iter (± 0) |
1.00 |
memory-usage-alloc-count/brave-list-1000-requests/alloc-count |
80015 allocs/iter (± 0) |
80015 allocs/iter (± 0) |
1 |
url_cosmetic_resources/brave-list |
184637 ns/iter (± 1941) |
185445 ns/iter (± 1200) |
1.00 |
cosmetic-class-id-match/brave-list |
3219801 ns/iter (± 840237) |
3228305 ns/iter (± 800958) |
1.00 |
This comment was automatically generated by workflow using github-action-benchmark.
Added support for parsing the
$tooption in network filters. Matching behavior remains unchanged.