-
Notifications
You must be signed in to change notification settings - Fork 178
pre-0.12.x => master #574
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
pre-0.12.x => master #574
Conversation
3869ee3 to
9763c33
Compare
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: 29cf12d | Previous: 3f09734 | Ratio |
|---|---|---|---|
rule-match-browserlike/brave-list |
1991942926 ns/iter (± 7538002) |
2062822761 ns/iter (± 6207839) |
0.97 |
rule-match-first-request/brave-list |
1091120 ns/iter (± 7198) |
1126665 ns/iter (± 9322) |
0.97 |
blocker_new/brave-list |
132721976 ns/iter (± 1001032) |
146929925 ns/iter (± 463260) |
0.90 |
blocker_new/brave-list-deserialize |
24291322 ns/iter (± 243802) |
23264715 ns/iter (± 60876) |
1.04 |
memory-usage/brave-list-initial |
10213344 ns/iter (± 3) |
10213344 ns/iter (± 3) |
1 |
memory-usage/brave-list-initial/max |
60612235 ns/iter (± 3) |
60612235 ns/iter (± 3) |
1 |
memory-usage/brave-list-initial/alloc-count |
996170 ns/iter (± 3) |
1231711 ns/iter (± 3) |
0.81 |
memory-usage/brave-list-1000-requests |
2692712 ns/iter (± 3) |
2692712 ns/iter (± 3) |
1 |
memory-usage/brave-list-1000-requests/alloc-count |
69464 ns/iter (± 3) |
71607 ns/iter (± 3) |
0.97 |
url_cosmetic_resources/brave-list |
190467 ns/iter (± 798) |
192394 ns/iter (± 2074) |
0.99 |
cosmetic-class-id-match/brave-list |
3383031 ns/iter (± 938484) |
3365434 ns/iter (± 902553) |
1.01 |
This comment was automatically generated by workflow using github-action-benchmark.
9763c33 to
99c10c3
Compare
99c10c3 to
d284e1b
Compare
src/filters/network.rs
Outdated
| #[deprecated(since = "0.11.1", note = "use get_tokens_optimized instead")] | ||
| pub fn get_tokens(&self) -> Vec<Vec<Hash>> { | ||
| match self.get_tokens_optimized() { | ||
| let mut tokens_buffer = TokensBuffer::default(); | ||
| match self.get_tokens_optimized(&mut tokens_buffer) { | ||
| FilterTokens::OptDomains(domains) => { | ||
| domains.into_iter().map(|domain| vec![domain]).collect() | ||
| domains.iter().map(|domain| vec![*domain]).collect() | ||
| } | ||
| FilterTokens::Other(tokens) => vec![tokens], | ||
| FilterTokens::Other(tokens) => vec![tokens.to_vec()], | ||
| FilterTokens::Empty => vec![], | ||
| } | ||
| } |
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.
since we're making a breaking version change, shall we remove this one also?
we can rename get_tokens_optimized back to get_tokens in the process
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.
also, I am open to making these pub(crate) to prevent needing similar breaking changes in the future
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.
Done. I also made pub(crate) related TokensBuffer and FilterTokens
| fn matches_test(&self, request: &request::Request) -> bool; | ||
| } | ||
|
|
||
| impl NetworkMatchable for NetworkFilter { |
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.
I think we can also make NetworkMatchable into a pub(crate) trait since it's only implemented for FlatNetworkFilter now
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.
Done. I also removed unused matches_test.
Maybe it makes sense to completely remove trait NetworkMatchable, but since it non-public, we can do it later.
458febb to
e56ec36
Compare
The PR reduces the amount of allocations by using arrayvec crate that allocates memory on a stack instead of a heap. * the number of allocations is reduced (-19%, memory-usage/brave-list-initial/alloc-count); * building time is improved (about -10%, memory-usage/brave-list-initial); * the token limit is increased up to 256; * the tests expectations were updated (one case hit the old token limit).
The PR removes impl NetworkMatchable for NetworkFilter and port the related tests to the flatbuffer impl (that we actually use in production)
Added: - `arrayvec` dependency Changed: - Improved performance and memory usage when parsing filters Removed: - `FilterTokens`, `get_tokens`, `get_tokens_optimized`, and `NetworkMatchable` are now crate-internal only
e56ec36 to
29cf12d
Compare
|
[puLL-Merge] - brave/adblock-rust@574 DescriptionThis PR upgrades the adblock-rust crate from version 0.11.1 to 0.12.0. The main changes focus on performance optimization by:
Possible Issues
Security Hotspots
Privacy HotspotsNo significant privacy issues identified in this PR. The changes are primarily performance optimizations and internal refactoring that don't affect data collection, storage, or transmission. ChangesChangesCargo.toml / Cargo.lock / js/Cargo.toml / package.json
src/utils.rs
src/filters/network.rs
src/filters/fb_network.rs
src/filters/fb_network_builder.rs
src/filters/network_matchers.rs
src/blocker.rs
src/engine.rs
src/regex_manager.rs
src/request.rs
tests/ (multiple files)
sequenceDiagram
participant Client
participant Engine
participant Blocker
participant FilterList
participant TokensBuffer
participant RegexManager
Client->>Engine: check_network_request(request)
Engine->>Blocker: check(request, resources)
Blocker->>Blocker: borrow_regex_manager()
Blocker->>RegexManager: get mutable reference
RegexManager-->>Blocker: RegexManagerRef
Blocker->>FilterList: check(request, regex_manager)
loop For each filter in list
FilterList->>TokensBuffer: create/clear buffer
FilterList->>NetworkFilter: get_tokens(&mut buffer)
NetworkFilter->>TokensBuffer: tokenize into buffer (stack allocated)
TokensBuffer-->>NetworkFilter: token references
NetworkFilter-->>FilterList: FilterTokens (borrowed slices)
FilterList->>NetworkFilter: matches(request, regex_manager)
NetworkFilter->>RegexManager: compile_if_needed(pattern)
RegexManager-->>NetworkFilter: compiled regex
NetworkFilter-->>FilterList: match result
end
FilterList-->>Blocker: BlockerResult
Blocker-->>Engine: BlockerResult
Engine-->>Client: BlockerResult
|
No description provided.