libgit2sharp - 迭代存储库的提交时出现性能问题?

标签 libgit2sharp

我只想显示存储库的前 100 次提交。我使用 linux-repo 来测试这一点:

        const int maxSize = 100;

        Stopwatch sw = new Stopwatch();
        Console.WriteLine( "Getting Commits in own Thread" );
        sw.Start();

        using( Repository repo = new Repository( path_to_linux_repo ) )
        {
            ICommitLog commits = repo.Commits.QueryBy( new CommitFilter { Since = "HEAD" } );

            int index = 0;
            foreach( Commit commit in commits )
            {
                if( index++ > maxSize ) break;                    
            }
        }

        sw.Stop();
        Console.WriteLine( "Took {0}ms for {1} entries", sw.ElapsedMilliseconds, maxSize ); 

这个简单的循环在我的机器上花费了 9000 多毫秒。当使用提交较少的存储库时,它的速度要快得多,但是为什么在具有大量提交的存储库中它如此慢? 另一个问题:是否可以只检索给定数量的提交,例如翻页 所有提交?

最佳答案

我可以在这里重现。这绝对是太长的时间了。看起来 libgit2 在返回之前正在将完整的图表排入队列,这对于给定的设置来说是一个错误。您介意提出一个问题吗?

至于检索多个提交,迭代是基于拉取的,因此您只能从存储库中获取所需的数量。提交日志实现了 IEnumerable,因此您可以使用您喜欢的任何 LINQ 方法(或者如本示例所示手动执行)。


更新:

这个bug相当尴尬,但是有一个PR to fix it 在 libgit2 中,它将在适当的时候进入 libgit2sharp 版本。修复后,此测试现在需要大约 80 毫秒。感谢您提出来。

更新2:

该修复现已在 LibGit2Sharp 的 vNext 分支中提供。

关于libgit2sharp - 迭代存储库的提交时出现性能问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22539288/

相关文章:

c# - 使用 libgit2sharp 从分支中提取最新版本

git - 如何在 LibGit2Sharp 中使用新的 CredentialsProvider?

libgit2sharp - 等同于 git difftool -y 和 libgit2sharp?

C# 如何使用 libgit2Sharp 读取提交时间

c# - 从 LibGit2Sharp 中的提交中获取修改/添加/删除的文件

c# - 'LibGit2Sharp.Core.NativeMethods' 的类型初始值设定项抛出异常

c# - Libgit2Sharp:获取两个标签之间的文件列表

c# - 如何使用 LibGit2Sharp 获取分支?

libgit2sharp - 使用 SSH 和 libgit2sharp 克隆一个 git 存储库

c# - LibGit2Sharp异常: repository path not owned by current user