-
Notifications
You must be signed in to change notification settings - Fork 978
bench: Add benchmarks for revset graph #9025
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
Open
ThierryBerger
wants to merge
1
commit into
jj-vcs:main
Choose a base branch
from
ThierryBerger:benchmark-log
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
bench: Add benchmarks for revset graph
This adds simple, isolated and reproducible benchmarks for revsets. ## Context - While working on #8968 ; performance was mentioned, as well as trying impacts on big repositories such as linux. Cloning a big repository to test performance is cumbersome, difficult to compare baseline for, and not intuitive. From what I understand, `jj bench log` is what's used right now by jj developers, with https://github.com/jj-vcs/jj/blob/main/cli/testing/bench-revsets-git.txt being a suggestion of revset to pass to. This file is regularly outdated so using it wasn't very fun. ## Details on this PR - This builds on what exists on this repository, within `lib/benches`. It seems a bit underused/old, but still on the repository so I'm hopeful that the design is still relevant. - No additional dependencies - Small by design, I want a baseline performance comparison for future discussions on #8968, or other topics. - Future possibilities: This is a simpler setup to run on a CI: `cargo bench`
- Loading branch information
commit 82ec9f47db70e9c7abefb261f124494f39773a87
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| // Copyright 2026 The Jujutsu Authors | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // https://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| //! Benchmarks for the revset graph iteration pipeline, approximating the cost | ||
| //! of `jj log` (excluding template rendering). Each benchmark iteration covers | ||
| //! revset evaluation and topo-grouped graph traversal — the two phases `jj log` | ||
| //! runs before rendering each commit. | ||
|
|
||
| use criterion::BenchmarkId; | ||
| use criterion::Criterion; | ||
| use criterion::criterion_group; | ||
| use criterion::criterion_main; | ||
| use itertools::Itertools as _; | ||
| use jj_lib::graph::TopoGroupedGraphIterator; | ||
| use jj_lib::revset::RevsetExpression; | ||
| use pollster::FutureExt as _; | ||
| use testutils::TestRepo; | ||
| use testutils::write_random_commit; | ||
| use testutils::write_random_commit_with_parents; | ||
|
|
||
| /// Benchmark over a long linear chain of hidden commits. | ||
| /// | ||
| /// Graph shape (N = chain length): | ||
| /// | ||
| /// tip (visible) | ||
| /// | | ||
| /// [N hidden commits] | ||
| /// | | ||
| /// root (visible) | ||
| /// | ||
| /// This exercises `edges_from_external_commit` (two-phase BFS) and | ||
| /// `count_hidden_to_visible` (the elided-count BFS) over a deep linear path. | ||
| fn bench_linear_chain(c: &mut Criterion) { | ||
| let mut group = c.benchmark_group("revset_graph/linear_chain"); | ||
| for &n in &[100usize, 1_000] { | ||
| // Build the repo once outside the measurement loop. | ||
| let test_repo = TestRepo::init(); | ||
| let mut tx = test_repo.repo.start_transaction(); | ||
| let root_visible = write_random_commit(tx.repo_mut()); | ||
| let mut prev = root_visible.clone(); | ||
| for _ in 0..n { | ||
| prev = write_random_commit_with_parents(tx.repo_mut(), &[&prev]); | ||
| } | ||
| let tip_visible = write_random_commit_with_parents(tx.repo_mut(), &[&prev]); | ||
| let repo = tx.commit("bench").block_on().unwrap(); | ||
|
|
||
| let expression = | ||
| RevsetExpression::commits(vec![root_visible.id().clone(), tip_visible.id().clone()]); | ||
|
|
||
| group.bench_with_input(BenchmarkId::from_parameter(n), &n, |b, _| { | ||
| b.iter(|| { | ||
| let revset = expression.clone().evaluate(repo.as_ref()).unwrap(); | ||
| TopoGroupedGraphIterator::new(revset.iter_graph(), |id| id) | ||
| .try_collect::<_, Vec<_>, _>() | ||
| .unwrap() | ||
| }); | ||
| }); | ||
| } | ||
| group.finish(); | ||
| } | ||
|
|
||
| /// Benchmark over a staircase of diamond-shaped hidden subgraphs. | ||
| /// | ||
| /// Graph shape for D=2 layers, W=3 branches (all intermediate commits hidden): | ||
| /// | ||
| /// tip (visible) | ||
| /// | | ||
| /// merge_1 (hidden) | ||
| /// / | \ | ||
| /// b0 b1 b2 (hidden) | ||
| /// \ | / | ||
| /// merge_0 (hidden) | ||
| /// / | \ | ||
| /// b0 b1 b2 (hidden) | ||
| /// \ | / | ||
| /// root (visible) | ||
| /// | ||
| /// Parameterized by D (depth = number of diamond layers) and W (width = | ||
| /// branches per layer). | ||
| fn bench_diamond_staircase(c: &mut Criterion) { | ||
| let mut group = c.benchmark_group("revset_graph/diamond_staircase"); | ||
| // (depth, width): depth = number of diamond layers, width = branches per layer | ||
| for &(depth, width) in &[(200usize, 2usize), (100, 4), (40, 10)] { | ||
| let test_repo = TestRepo::init(); | ||
| let mut tx = test_repo.repo.start_transaction(); | ||
| let root_visible = write_random_commit(tx.repo_mut()); | ||
| let mut base = root_visible.clone(); | ||
| for _ in 0..depth { | ||
| let branches: Vec<_> = (0..width) | ||
| .map(|_| write_random_commit_with_parents(tx.repo_mut(), &[&base])) | ||
| .collect(); | ||
| let branch_refs: Vec<&_> = branches.iter().collect(); | ||
| base = write_random_commit_with_parents(tx.repo_mut(), &branch_refs); | ||
| } | ||
| let tip_visible = write_random_commit_with_parents(tx.repo_mut(), &[&base]); | ||
| let repo = tx.commit("bench").block_on().unwrap(); | ||
|
|
||
| let expression = | ||
| RevsetExpression::commits(vec![root_visible.id().clone(), tip_visible.id().clone()]); | ||
|
|
||
| let label = format!("d{depth}_w{width}"); | ||
| group.bench_with_input(BenchmarkId::from_parameter(&label), &label, |b, _| { | ||
| b.iter(|| { | ||
| let revset = expression.clone().evaluate(repo.as_ref()).unwrap(); | ||
| TopoGroupedGraphIterator::new(revset.iter_graph(), |id| id) | ||
| .try_collect::<_, Vec<_>, _>() | ||
| .unwrap() | ||
| }); | ||
| }); | ||
| } | ||
| group.finish(); | ||
| } | ||
|
|
||
| criterion_group!(benches, bench_linear_chain, bench_diamond_staircase); | ||
| criterion_main!(benches); | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.