rust-lang / rust-lang/git2-rs

Diff foreach takes too long, causing performance bottleneck

Open
#1,125 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
2.1k
Forks
450
Avg merge
11m
Merged PRs (30d)
1

Description

Hi, this is my code:

let mut commits = vec![];
while let Ok(parent) = commit.parent(0) {
    if let Ok(now) = commit.tree() {
        if let Ok(pre) = parent.tree() {
            if let Ok(diff) = self.repository.diff_tree_to_tree(
                Some(&tree),
                Some(&parent.tree().unwrap()),
                Some(&mut DiffOptions::new())
            ){
                let mut deltas = vec![];
                diff.foreach(&mut |delta, _ | {
                    deltas.push(PathBuf::from(delta.new_file().path().unwrap_or(PathBuf::new().as_path())));
                    true
                },None, None,None);
                commits.push((Commit {
                    id: commit.id().to_string(),
                    msg: commit.message().unwrap_or("").to_string(),
                    time: chrono::DateTime::from_timestamp(commit.time().seconds(),0).unwrap().to_rfc2822(),
                    author: commit.author().name().unwrap_or("").to_string(),
                    email: commit.author().email().unwrap_or("").to_string(),
                },deltas));
                
            }
        }
    }
    commit = parent;
}

The average execution time is about two minutes, and I don't know how to improve it.
I would be grateful if there is any solution

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by profiling the shown loop, especially diff_tree_to_tree and diff.foreach, to identify whether tree creation, diff computation, or delta collection causes the reported two-minute runtime. There is no file or test named; done would require a demonstrated improvement to this execution time without changing the collected commit and path data.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.