Skip to content
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

Setup basic perf CI #417

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .github/workflows/perf-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# CI for performance benchmarking
# Domains of interest:
# * startup speed (== to parse and load all rules)
# * network filter matching (== the avg time to check a request)
# * first request matching delay (== time to check the first request)
name: Performance CI

on:
push:
branches: [ master ]
pull_request:

permissions:
contents: write
pages: write
pull-requests: write

jobs:
benchmark:
name: Performance benchmarking
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

- name: setup python
uses: actions/setup-python@v4

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable

- name: Bench network filter matching
run: cargo bench --bench bench_matching rule-match-browserlike/brave-list -- --output-format bencher | tee -a output.txt

- name: Bench first request matching delay
run: cargo bench --bench bench_matching rule-match-first-request -- --output-format bencher | tee -a output.txt

- name: Bench startup speed
run: cargo bench --bench bench_rules blocker_new/brave-list -- --output-format bencher | tee -a output.txt

- name: Store benchmark result
uses: benchmark-action/github-action-benchmark@v1
with:
name: Rust Benchmark
tool: 'cargo'
output-file-path: output.txt
github-token: ${{ secrets.GITHUB_TOKEN }}
alert-threshold: '130%' # fails on +30% regression
comment-on-alert: true
fail-on-alert: true
comment-always: true
56 changes: 46 additions & 10 deletions benches/bench_matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ fn bench_matching_only(blocker: &Blocker, resources: &ResourceStorage, requests:
(matches, passes)
}

type ParsedRequest = (String, String, String, String, bool);

fn bench_rule_matching_browserlike(
blocker: &Engine,
requests: &Vec<(String, String, String, String, bool)>,
requests: &Vec<ParsedRequest>,
) -> (u32, u32) {
let mut matches = 0;
let mut passes = 0;
Expand Down Expand Up @@ -331,27 +333,60 @@ fn rule_match_browserlike_comparable(c: &mut Criterion) {
.collect::<Vec<_>>()
}

let elep_req = requests_parsed(&requests);
let el_req = elep_req.clone();
let slim = elep_req.clone();
let requests = requests_parsed(&requests);

group.bench_function("el+ep", move |b| {
group.bench_function("el+ep", |b| {
let rules = rules_from_lists(&[
"data/easylist.to/easylist/easylist.txt",
"data/easylist.to/easylist/easyprivacy.txt",
]);
let engine = Engine::from_rules_parametrised(rules, Default::default(), false, true);
b.iter(|| bench_rule_matching_browserlike(&engine, &elep_req))
b.iter(|| bench_rule_matching_browserlike(&engine, &requests))
});
group.bench_function("el", move |b| {
group.bench_function("el", |b| {
let rules = rules_from_lists(&["data/easylist.to/easylist/easylist.txt"]);
let engine = Engine::from_rules_parametrised(rules, Default::default(), false, true);
b.iter(|| bench_rule_matching_browserlike(&engine, &el_req))
b.iter(|| bench_rule_matching_browserlike(&engine, &requests))
});
group.bench_function("slimlist", move |b| {
group.bench_function("slimlist", |b| {
let rules = rules_from_lists(&["data/slim-list.txt"]);
let engine = Engine::from_rules_parametrised(rules, Default::default(), false, true);
b.iter(|| bench_rule_matching_browserlike(&engine, &slim))
b.iter(|| bench_rule_matching_browserlike(&engine, &requests))
});
group.bench_function("brave-list", |b| {
let rules = rules_from_lists(&["data/brave/brave-main-list.txt"]);
let engine = Engine::from_rules_parametrised(rules, Default::default(), false, true);
b.iter(|| bench_rule_matching_browserlike(&engine, &requests))
});

group.finish();
}

fn rule_match_first_request(c: &mut Criterion) {
let mut group = c.benchmark_group("rule-match-first-request");

group.sample_size(10);

let requests: Vec<ParsedRequest> = vec![(
"https://example.com".to_string(),
"example.com".to_string(),
"example.com".to_string(),
"document".to_string(),
false,
)];

group.bench_function("brave-list", |b| {
b.iter_with_setup(
|| {
// Setup: Create a fresh engine for each iteration
let rules = rules_from_lists(&["data/brave/brave-main-list.txt"]);
Engine::from_rules_parametrised(rules, Default::default(), false, true)
},
|engine| {
// Measured: Single request check with fresh engine
bench_rule_matching_browserlike(&engine, &requests)
}
)
});

group.finish();
Expand All @@ -363,6 +398,7 @@ criterion_group!(
rule_match_parsed_el,
rule_match_parsed_elep_slimlist,
rule_match_browserlike_comparable,
rule_match_first_request,
serialization,
deserialization
);
Expand Down
10 changes: 6 additions & 4 deletions benches/bench_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ fn list_parse(c: &mut Criterion) {
fn get_blocker(rules: impl IntoIterator<Item=impl AsRef<str>>) -> Blocker {
let (network_filters, _) = adblock::lists::parse_filters(rules, false, Default::default());

println!("Got {} network filters", network_filters.len());
atuchin-m marked this conversation as resolved.
Show resolved Hide resolved

let blocker_options = BlockerOptions {
enable_optimizations: true,
};
Expand All @@ -99,12 +97,16 @@ fn blocker_new(c: &mut Criterion) {
group.throughput(Throughput::Elements(1));
group.sample_size(10);

let rules: Vec<_> = rules_from_lists(&[
let easylist_rules: Vec<_> = rules_from_lists(&[
"data/easylist.to/easylist/easylist.txt",
"data/easylist.to/easylist/easyprivacy.txt",
]).collect();
let brave_list_rules: Vec<_> = rules_from_lists(&[
"data/brave/brave-main-list.txt",
]).collect();

group.bench_function("el+ep", move |b| b.iter(|| get_blocker(&rules)));
group.bench_function("el+ep", move |b| b.iter(|| get_blocker(&easylist_rules)));
group.bench_function("brave-list", move |b| b.iter(|| get_blocker(&brave_list_rules)));

group.finish();
}
Expand Down
Loading
Loading