Skip to content

Commit 85f134d

Browse files
committed
add benchmark for branch-listing
1 parent b93b335 commit 85f134d

File tree

9 files changed

+320
-13
lines changed

9 files changed

+320
-13
lines changed

Cargo.lock

Lines changed: 149 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/gitbutler-branch-actions/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,12 @@ gitbutler-git = { workspace = true, features = ["test-askpass-path"] }
4747
glob = "0.3.1"
4848
serial_test = "3.1.1"
4949
tempfile = "3.10"
50+
criterion = "0.5.1"
51+
52+
[features]
53+
## Only enabled when benchmark runs are performed.
54+
benches = ["gitbutler-git/benches"]
55+
56+
[[bench]]
57+
name = "branches"
58+
harness = false
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
To run benchmarks, add the `benches` feature.
2+
3+
```shell
4+
cargo bench --features benches
5+
```
6+
7+
It's used to get past a safety check in `gitbutler-git`.
8+
9+
For faster compile times, specify the benchmark file directly, i.e.
10+
11+
```shell
12+
cargo bench --bench branches --features benches
13+
```
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput};
2+
use gitbutler_branch_actions::list_branches;
3+
use gitbutler_command_context::CommandContext;
4+
5+
pub fn project_ctx(name: &str, script: &str) -> CommandContext {
6+
gitbutler_testsupport::read_only::fixture(script, name).unwrap()
7+
}
8+
9+
pub fn benchmark_list_branches(c: &mut Criterion) {
10+
for (bench_name, (repo_name, script_name)) in [
11+
(
12+
"list-branches[many local branches]",
13+
("many-local", "branch-benches.sh"),
14+
),
15+
(
16+
"list-branches[tiny repo]",
17+
("one-vbranch-on-integration-two-remotes", "for-listing.sh"),
18+
),
19+
(
20+
"list-branches[many local branches [packed]]",
21+
("many-local-packed", "branch-benches.sh"),
22+
),
23+
(
24+
"list-branches[many local branches [tracked]]",
25+
("many-local-tracked", "branch-benches.sh"),
26+
),
27+
(
28+
"list-branches[many local branches [tracked & packed]]",
29+
("many-local-tracked-packed", "branch-benches.sh"),
30+
),
31+
] {
32+
let mut group = c.benchmark_group(bench_name);
33+
let ctx = project_ctx(repo_name, script_name);
34+
group.throughput(Throughput::Elements(1));
35+
group
36+
.bench_function("no filter", |b| {
37+
b.iter(|| list_branches(black_box(&ctx), None, None))
38+
})
39+
.bench_function("name-filter rejecting all", |b| {
40+
b.iter(|| list_branches(black_box(&ctx), None, Some(vec!["not available".into()])))
41+
});
42+
}
43+
}
44+
45+
criterion_group!(benches, benchmark_list_branches);
46+
criterion_main!(benches);

crates/gitbutler-branch-actions/src/branch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub fn list_branches(
7373
return true;
7474
}
7575

76-
// If the virtual virtual branch has a local branch, keep the grouping
76+
// If the virtual branch has a local branch, keep the grouping
7777
if branch.has_local {
7878
return true;
7979
};

0 commit comments

Comments
 (0)