libgit2 / libgit2/libgit2sharp
Fetching history for a file VERY slow using libgit2sharp
Nessuno ha ancora preso questa issue.
- Lingua principale
- C#
- Stelle
- 3.5k
- Fork
- 925
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con la riproduzione in C# usando Repository.Commits.QueryBy(fileName, filter) e la relativa impostazione CommitFilter.SortBy, quindi confrontala con il tempo riportato per git --no-pager log. Analizza il divario di prestazioni e il motivo per cui SortBy = None viene rifiutato, usando come contesto la issue correlata di libgit2, la 4428. Il lavoro è completato quando sono state stabilite la causa e una risoluzione attuabile per le prestazioni della cronologia dei file.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- csharp, git
- Ambito
- devtools, performance
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 38/100