[perf, memory] Add single/multi_pattern to optimize memory usage (0.13.x)#643
Merged
Conversation
There was a problem hiding this comment.
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.
antonok-edm
reviewed
May 12, 2026
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>>), | ||
| } |
Collaborator
There was a problem hiding this comment.
would be nice to document the rationale for the optimization so an agent doesn't try to "fix" it back
57e0e14 to
1c5e70a
Compare
antonok-edm
approved these changes
May 12, 2026
There was a problem hiding this comment.
⚠️ 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.
1c5e70a to
e2f4c6f
Compare
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 storepatternsas 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.