Skip to content

Commit

Permalink
improve performance of commit-graph variant ever-so-slightly
Browse files Browse the repository at this point in the history
In practice, what really matters is to reuse as much of the
previous computation as possible.

Re-using the graph (or its menory) doesn't do much, but reusing
the parsed commits would be a huge benefit when running many
queries after another.
  • Loading branch information
Byron committed Aug 26, 2024
1 parent 6d8612c commit 18c2fc4
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions gix-revision/src/merge_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ pub(crate) mod function {
others: &[ObjectId],
graph: &mut Graph<'_, '_, Flags>,
) -> Result<Option<Vec<ObjectId>>, Error> {
let _span = gix_trace::coarse!("gix_revision::merge_base()", ?first, ?others,);
let _span = gix_trace::coarse!("gix_revision::merge_base()", ?first, ?others);
if others.is_empty() || others.contains(&first) {
return Ok(Some(vec![first]));
}

graph.clear();
let bases = paint_down_to_common(first, others, graph)?;
graph.clear();

Expand All @@ -65,6 +66,7 @@ pub(crate) mod function {
if commits.is_empty() {
return Ok(Vec::new());
}
let _span = gix_trace::detail!("gix_revision::remove_redundant()", num_commits = %commits.len());
let sorted_commits = {
let mut v = commits.to_vec();
v.sort_by(|a, b| a.1.cmp(&b.1));
Expand Down Expand Up @@ -217,11 +219,10 @@ pub(crate) mod function {
type Error = gix_object::decode::Error;

fn try_from(commit: LazyCommit<'_, '_>) -> Result<Self, Self::Error> {
let (generation, timestamp) = commit.generation_and_timestamp()?;
Ok(GenThenTime {
generation: commit
.generation()
.unwrap_or(gix_commitgraph::GENERATION_NUMBER_INFINITY),
time: commit.committer_timestamp()?,
generation: generation.unwrap_or(gix_commitgraph::GENERATION_NUMBER_INFINITY),
time: timestamp,
})
}
}
Expand Down

0 comments on commit 18c2fc4

Please sign in to comment.