libgit2 / libgit2/libgit2sharp
Performance regression when reading files from the tree in parallel
まだ誰も着手していません。
- 主要言語
- C#
- スター
- 3.5k
- フォーク
- 925
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
Reproduction steps
- Add the following test cases in
CommitFixture.cs:
[Fact]
public void CanReadCommit()
{
var timer = new Stopwatch();
var fileContents = new ConcurrentStack<string>();
var path = SandboxStandardTestRepo();
using (var repo = new Repository(path))
{
var latestCommit = repo.Head.Tip;
var tree = latestCommit.Tree;
timer.Start();
for (var i = 0; i < 100000; i++)
{
fileContents.Push(ReadEntry("1.txt", tree));
fileContents.Push(ReadEntry("README", tree));
fileContents.Push(ReadEntry("new.txt", tree));
}
timer.Stop();
testOutputHelper.WriteLine($"Took: {timer.ElapsedMilliseconds.ToString()}ms");
Assert.Equal(300000, fileContents.Count);
}
}
[Fact]
public void CanReadCommitParallel()
{
var timer = new Stopwatch();
var fileContents = new ConcurrentStack<string>();
var path = SandboxStandardTestRepo();
using (var repo = new Repository(path))
{
var latestCommit = repo.Head.Tip;
var tree = latestCommit.Tree;
timer.Start();
var fileNames = new List<string>() {"1.txt", "README", "new.txt"}.AsEnumerable();
Parallel.ForEach(fileNames, (fileName) =>
{
for (var i = 0; i < 100000; i++)
{
fileContents.Push(ReadEntry(fileName, tree));
}
});
timer.Stop();
testOutputHelper.WriteLine($"Took: {timer.ElapsedMilliseconds.ToString()}ms");
Assert.Equal(300000, fileContents.Count);
}
}
private static string ReadEntry(string name, Tree tree)
{
var treeEntry = tree[name];
if (treeEntry != null && treeEntry.Target is Blob blob)
{
return blob.GetContentText();
}
throw new InvalidOperationException($"{name} must be a Blob");
}
- Run against version 0.27.0-preview-0119 (commit: 6329bea). On my machine,
CanReadCommitParalleltakes 1417ms andCanReadCommittakes 2971ms (which is fine) - Checkout the latest version or the latest release
- Run the test again. On my machine,
CanReadCommitParalleltakes 3731ms andCanReadCommittakes 3250ms!
Expected behavior
Reading files in parallel should be faster than reading files sequentially from the git tree.
Actual behavior
It seems that reading files from the tree in parallel (multi-thread) is not faster. I did a git bisect and it seems that this regression was introduced in https://github.com/libgit2/libgit2sharp/commit/21d4f13ac7c739a5526cf088fbd8765d4ad12f57
Version of LibGit2Sharp (release number or SHA1)
Versions after https://github.com/libgit2/libgit2sharp/commit/21d4f13ac7c739a5526cf088fbd8765d4ad12f57
Operating system(s) tested; .NET runtime tested
.NET 6 and .NET 7.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
CommitFixture.cs で、レポートに記載されているバージョンに対する逐次実行と Parallel.ForEach の再現コードを追加して実行するところから始めてください。Commit 21d4f13ac7c739a5526cf088fbd8765d4ad12f57 前後の tree と blob の読み取り動作を .NET 6 と .NET 7 で比較してください。並列読み取りで正しい件数が維持され、比較可能な実行で逐次読み取りより高速であれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- csharp, git
- 領域
- performance
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 42/100