Skip to content

Added parser for $to option in NetworkFilter.#689

Draft
boocmp wants to merge 25 commits into
masterfrom
to_op
Draft

Added parser for $to option in NetworkFilter.#689
boocmp wants to merge 25 commits into
masterfrom
to_op

Conversation

@boocmp

@boocmp boocmp commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

atuchin-m and others added 21 commits June 30, 2026 09:39
The PR:
* removes IS_BADFILTER from NetworkFilterMask
* adds NetworkFilterFeatureMask to store parse-only features
* rids off get_id_without_badfilter in favor of get_id()
* removes impl NetworkFilterMaskHelper for CheckedResult
The PR refactors `NetworkFilterMask` by moving some parse-only bits to `NetworkFilterFeaturesMask`.
* Refactor IS_REMOVEPARAM
* Refactor IS_GENERIC_HIDE
* Refactor IS_CSP
* Refactor IS_REDIRECT + ALSO_BLOCK_REDIRECT
* Fix compilation and tests
* remove unused import
* Add feature_mask to get_id()
The PR adjusts mask default value to consume less memory.
Flatbuffer builder doesn't serialize the mask if it's equal to the default.
The current default covers about 50% of the network rules and saves 200KB+ of memory.
…3.x) (#643)

The PR optimizes memory usage and building time by adding a simplified pattern storage.

Most filters (95%+) have patterns.len() <= 1. Despite that fact we always store patterns as a vector.
This implies storing an extra pointer (to the vector itself) + the vector length.

The PR adds an optional ability to store pattern as a single string eliminating the overhead above.
The PR introduces a new API to move from Vec<SomeFilter> in FilterSet.
This is a necessary step to make streaming parsing work.
The PR refactor the filter parsing code to allow processing filters one-by-one.
* new_with_filter_set parses filter one by one and immediately drops them after processing.
* The filters, matched to bad filters, are always serialized. The offsets are dropped from the hash table on the last stage. The negative impact is minimal, because $badfilter is rare thing.
* get_tokens uses an extra output param tokens_buffer to avoid unwanted allocations.

The PR dramatically reduces allocation count (-25%) and peak memory usage (about -50%).
The PR makes NetworkFilter::parse reuse the original string via &str or Cow<>
* removes an extra String alloc in get_id();
* uses rustc-hash as the impl which is more reliable and a little bit faster;
@boocmp boocmp self-assigned this Jul 1, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rust Benchmark

Details
Benchmark suite Current: f466e19 Previous: 5d182e5 Ratio
rule-match-browserlike/brave-list 2377131164 ns/iter (± 12597630) 2241363322 ns/iter (± 47317273) 1.06
rule-match-first-request/brave-list 980119 ns/iter (± 4019) 1216052 ns/iter (± 6861) 0.81
blocker_new/brave-list 105874415 ns/iter (± 958314) 138839767 ns/iter (± 844690) 0.76
blocker_new/brave-list-deserialize 31383767 ns/iter (± 157085) 31752836 ns/iter (± 821884) 0.99
memory-usage-final/brave-list-initial 10881484 B/iter (± 0) 11355668 B/iter (± 0) 0.96
memory-usage-final/brave-list-1000-requests 2818515 B/iter (± 0) 2612449 B/iter (± 0) 1.08
memory-usage-max/brave-list-initial/max 27809166 B/iter (± 0) 63576475 B/iter (± 0) 0.44
memory-usage-alloc-count/brave-list-initial/alloc-count 281692 allocs/iter (± 0) 859963 allocs/iter (± 0) 0.33
memory-usage-alloc-count/brave-list-1000-requests/alloc-count 81523 allocs/iter (± 0) 74018 allocs/iter (± 0) 1.10
url_cosmetic_resources/brave-list 156738 ns/iter (± 2936) 191870 ns/iter (± 955) 0.82
cosmetic-class-id-match/brave-list 2630633 ns/iter (± 682053) 3552152 ns/iter (± 986336) 0.74

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Rust Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.10.

Benchmark suite Current: f466e19 Previous: 5d182e5 Ratio
memory-usage-alloc-count/brave-list-1000-requests/alloc-count 81523 allocs/iter (± 0) 74018 allocs/iter (± 0) 1.10

This comment was automatically generated by workflow using github-action-benchmark.

@boocmp
boocmp force-pushed the to_op branch 4 times, most recently from fa735eb to e742aca Compare July 1, 2026 11:23
@antonok-edm
antonok-edm force-pushed the 0.13.x branch 5 times, most recently from 68a9766 to a71b805 Compare July 9, 2026 18:27
Base automatically changed from 0.13.x to master July 9, 2026 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants