Skip to content

Diff foreach takes too long, causing performance bottleneck #1125

@lazhenyi

Description

@lazhenyi

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions