libgit2 / libgit2/libgit2sharp
Fetching history for a file VERY slow using libgit2sharp
還沒有人認領這個 Issue。
- 主要語言
- C#
- 星號
- 3.5k
- 分支
- 925
- PR 合併指標
- 30 天內沒有已合併 PR
描述
I am attempting to use libgit2sharp to get the list of commits for a specific file in a repository. The code works, but it is VERY slow. How can I get git command line like performance from libgit2sharp?
Reproduction steps
Run the following code:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using LibGit2Sharp;
namespace GitHistoryTime
{
class Program
{
static void Main(string[] args)
{
if (args.Length < 2)
{
Console.WriteLine("Format is GitHistoryTime ");
}
else
{
string repoName = args[0];
string fileName = args[1];
Stopwatch stopwatch = System.Diagnostics.Stopwatch.StartNew();
Repository repo = new Repository(repoName);
if (repo == null)
{
Console.WriteLine("Could not find git repository for " + repoName);
}
else
{
CommitFilter filter = new CommitFilter
{
SortBy = CommitSortStrategies.Topological
};
IEnumerable log = repo.Commits.QueryBy(fileName, filter);
if (log != null)
{
foreach (LogEntry entry in log)
{
Console.WriteLine(entry.Commit.Sha);
}
}
Console.WriteLine("Time to get the log: {0}", stopwatch.Elapsed.ToString());
}
}
}
}
}
Expected behavior
I would expect to get times similar to doing git --no-pager log --fileName. On my system, git took 0.43 seconds to return the full history
Actual behavior
On my machine, the above code took 6 minutes and 45 seconds! That is roughly 800 times slower than the git command line.
Due to the comments in https://github.com/libgit2/libgit2/issues/4428, I first tried to use a sort strategy of None, but LibGit2Sharp threw an exception that None was not valid. Why?
Version of LibGit2Sharp (release number or SHA1)
7fc4be5193dbdd08538b4b150332b5a73770e0f6
Operating system(s) tested; .NET runtime tested
Windows 10 2004 .NET 4.6.1
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
先使用 Repository.Commits.QueryBy(fileName, filter) 及其 CommitFilter.SortBy 設定進行 C# 重現,然後將其與報告中的 git --no-pager log 耗時進行比較。調查效能差距以及 SortBy = None 被拒絕的原因,並以相關的 libgit2 issue 4428 作為背景。確立檔案歷程效能問題的原因和可執行的解決方案後,即視為完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- csharp, git
- 領域
- devtools, performance
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 38/100