Skip to content

Conversation

@atuchin-m
Copy link
Collaborator

@atuchin-m atuchin-m commented Nov 5, 2025

The PR reduces the amount of allocation by introducing a new struct StackVector that allocates memory outside 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 (-11-15%, memory-usage/brave-list-initial);
  • the tests expectations were updated, because before one case hits the token limit.

Also, I tried to use MaybeUinit + unsafe to avoid zeroing the memory, but it turns out it doesn't give any profit now, so let's stash that idea for future usage.

@atuchin-m atuchin-m self-assigned this Nov 5, 2025
Copy link

@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

Benchmark suite Current: d3df508 Previous: 3feffc9 Ratio
rule-match-browserlike/brave-list 2074493135 ns/iter (± 17176018) 2089868473 ns/iter (± 20161585) 0.99
rule-match-first-request/brave-list 1105573 ns/iter (± 21061) 1119548 ns/iter (± 13496) 0.99
blocker_new/brave-list 138914815 ns/iter (± 1184608) 155371876 ns/iter (± 816509) 0.89
blocker_new/brave-list-deserialize 28715496 ns/iter (± 1164468) 29471071 ns/iter (± 1288134) 0.97
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) 2692696 ns/iter (± 3) 1.00
memory-usage/brave-list-1000-requests/alloc-count 69464 ns/iter (± 3) 71591 ns/iter (± 3) 0.97
url_cosmetic_resources/brave-list 192596 ns/iter (± 977) 192025 ns/iter (± 3720) 1.00
cosmetic-class-id-match/brave-list 3407715 ns/iter (± 928969) 3479706 ns/iter (± 936426) 0.98

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

@atuchin-m atuchin-m marked this pull request as ready for review November 12, 2025 12:33
@atuchin-m atuchin-m requested a review from a team as a code owner November 12, 2025 12:33
let msg = "The number of blocked/passed requests has changed. ".to_string()
+ "If this is expected, update the expected values in the test.";
assert_eq!((blocked, passes), (106860, 136085), "{msg}");
assert_eq!((blocked, passes), (106861, 136084), "{msg}");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this expected ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I mentioned in the PR description: we hits the token limits for one rule.
If you take master and increase the limits, you will get the same behavior.

Copy link
Collaborator

Choose a reason for hiding this comment

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

nvm, the reason is in the descr

}

impl<T: Default, const MAX_SIZE: usize> StackVector<T, MAX_SIZE> {
pub fn push(&mut self, value: T) -> bool {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you mind to panic instead of returning bool ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I believe we shouldn't panic by default.
If a caller need, it can use if (!push(..)) { panic!(...); }

github-actions[bot]

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants