Skip to content

[perf, memory] Add single/multi_pattern to optimize memory usage (0.13.x)#643

Merged
atuchin-m merged 5 commits into
0.13.xfrom
add-single-multi-pattern
May 12, 2026
Merged

[perf, memory] Add single/multi_pattern to optimize memory usage (0.13.x)#643
atuchin-m merged 5 commits into
0.13.xfrom
add-single-multi-pattern

Conversation

@atuchin-m
Copy link
Copy Markdown
Collaborator

@atuchin-m atuchin-m commented May 12, 2026

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.

@atuchin-m atuchin-m self-assigned this May 12, 2026
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

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: e2f4c6f Previous: ae351f4 Ratio
rule-match-browserlike/brave-list 2283207873 ns/iter (± 13194906) 2166883725 ns/iter (± 9115974) 1.05
rule-match-first-request/brave-list 1244289 ns/iter (± 46820) 1234442 ns/iter (± 10355) 1.01
blocker_new/brave-list 153585269 ns/iter (± 978055) 145404750 ns/iter (± 734465) 1.06
blocker_new/brave-list-deserialize 37941517 ns/iter (± 1376026) 28055076 ns/iter (± 456630) 1.35
memory-usage/brave-list-initial 10816824 ns/iter (± 3) 11354704 ns/iter (± 3) 0.95
memory-usage/brave-list-initial/max 63576624 ns/iter (± 3) 63576624 ns/iter (± 3) 1
memory-usage/brave-list-initial/alloc-count 997859 ns/iter (± 3) 983703 ns/iter (± 3) 1.01
memory-usage/brave-list-1000-requests 2612592 ns/iter (± 3) 2612608 ns/iter (± 3) 1.00
memory-usage/brave-list-1000-requests/alloc-count 74187 ns/iter (± 3) 74219 ns/iter (± 3) 1.00
url_cosmetic_resources/brave-list 200250 ns/iter (± 1480) 190794 ns/iter (± 1339) 1.05
cosmetic-class-id-match/brave-list 3317205 ns/iter (± 895873) 3477527 ns/iter (± 941705) 0.95

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

@atuchin-m atuchin-m requested review from antonok-edm and boocmp May 12, 2026 20:31
@atuchin-m atuchin-m marked this pull request as ready for review May 12, 2026 20:31
Comment thread src/filters/fb_network.rs
Comment on lines 12 to 17
/// A list of string parts that can be matched against a URL.
pub(crate) struct FlatPatterns<'a> {
patterns: Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<&'a str>>>,
pub(crate) enum FlatPatterns<'a> {
Empty,
Single(&'a str),
Multi(flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<&'a str>>),
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

would be nice to document the rationale for the optimization so an agent doesn't try to "fix" it back

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

(I added it)

@antonok-edm antonok-edm force-pushed the add-single-multi-pattern branch from 57e0e14 to 1c5e70a Compare May 12, 2026 21:42
@atuchin-m atuchin-m changed the title [perf, memory] Add single/multi_pattern to optimize memory usage [perf, memory] Add single/multi_pattern to optimize memory usage (0.13.x) May 12, 2026
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

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: e2f4c6f Previous: ae351f4 Ratio
blocker_new/brave-list-deserialize 37941517 ns/iter (± 1376026) 28055076 ns/iter (± 456630) 1.35

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

@atuchin-m atuchin-m force-pushed the add-single-multi-pattern branch from 1c5e70a to e2f4c6f Compare May 12, 2026 21:53
@atuchin-m atuchin-m merged commit 454bcf9 into 0.13.x May 12, 2026
6 of 7 checks passed
@atuchin-m atuchin-m deleted the add-single-multi-pattern branch May 12, 2026 21:59
antonok-edm pushed a commit that referenced this pull request May 12, 2026
…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.
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.

2 participants