Repository navigation
Description
Environment:
libgit2sharp version: 0.24.1 from NuGet
.NET version: 4.5
OS: Windows 7, 32 bit.
CPU: Intel Core i7 @ 1.8 GHz.
storage: local SSD
Test case:
- Clone a large Git repo. (I try with https://github.com/python/cpython ).
- Run git log example on this repo.
Expected results:
Should be almost instant, because of "Take(15)" is limiting to just 15 commits.
The time should be similar to running git log -15 | cat from command line, which is almost instant to me.
Actual results:
It takes about 1.5-2 seconds to start iterating over the commits.
Notes:
The iteration time doesn't change significantly if you change to Take(10000) or Take(3).
It seems that it reads the entire history (or a huge chunk of it) into memory before the iteration starts.
If have changed the test sample to sleep after every 1000 items. It has shown that there's almost no significant delay for reading over the first 10K after it gets to the first item.
The task manager shows that my process takes about 6 Mb before the loop starts, and about 80 Mb on the first line of the loop (Console.WriteLine) right after it starts, which also indicates that.
Also this is a screenshot of the .NET profiler that shows that the most of the time is spent inside NativeMethods.git_revwalk_next, which I don't know how to profile inside (is it a C function?).
Question: Is there a workaround? I would like to get a few commits really fast by something like Commits.Skip(N).Take(50). Is there an alternative API that can be used for this use case? Is there a setting somewhere that tweaks how much of the history does it load/preload internally?
Activity
ethomson commentedon Mar 29, 2018
It is a C function, yes. (That's libgit2 itself.) And yes, that probably does need to walk the entirety of history in order to sort it properly. It's not clear to me immediately whether this is a LibGit2Sharp issue, a libgit2 issue, or simply a function of the size of your repository. How long does
git log --graphtake?battlmonstr commentedon Mar 29, 2018
A minimal code test example:
Outputs:
battlmonstr commentedon Mar 29, 2018
git log --graphtakes a about that time - 1.4 sec:Is there a way to disable "--graph" somehow in libgit2sharp or libgit2?
ethomson commentedon Mar 29, 2018
You may have luck with
CommitSortStrategiesbattlmonstr commentedon Mar 29, 2018
Don't see an easy way to test this. CommitLog constructors are "internal" and the class is "sealed", so can't pass or redefine "SortBy". Maybe I'll try reflection. The hardcoded strategy is CommitSortStrategies.Time.
battlmonstr commentedon Mar 29, 2018
Changing a sort strategy doesn't make any significant difference.
Here's my test code:
battlmonstr commentedon Mar 29, 2018
Related issue: libgit2/libgit2#4428
battlmonstr commentedon Mar 29, 2018
Trying an older version of libgit2sharp, it used to work fast indeed:
Actually it seems that "Reverse" and "Topological" modes became quite faster (2x), but "Time" is much much slower.
Still trying to find the first broken version.
battlmonstr commentedon Mar 29, 2018
This is a regression in 0.23 between
libgit2sharp 0.23 + LibGit2Sharp.NativeBinaries.1.0.163
libgit2sharp 0.22 + LibGit2Sharp.NativeBinaries.1.0.129
0.22 WFM.
carlosmn commentedon Apr 5, 2018
This is probably due to what libgit2/libgit2#4606 is fixing
nebosite commentedon Dec 18, 2018
I have a really big repository (many GB) and repository.Commits.Take(100) takes around 200 seconds to run. Compare to git log -n 100 which takes about 1 second. The culprit is this line in libgit2sharp:
battlmonstr commentedon Feb 16, 2019
Hello. Just reading up and trying to catch up with the progress done on this issue in libgit2 + libgit2sharp.
The good news is that some related fixes were merged and included in libgit2sharp v0.26.0 (based on libgit2 v0.28.0):
libgit2/libgit2#4606
libgit2/libgit2#4809
and it improved performance of the commit log with CommitSortStrategies.None option. Good stuff! 👍
On the opposite side, the CommitSortStrategies.Time option became about 30% slower. Testing on the same repo:
libgit2sharp v0.26.0 - 1.7-1.8 sec
libgit2sharp v0.23.0 - 1.3 sec
Thinking more about this, I would actually like default
.Timeoption to be fast too.From some of the comments I have understood that when you need sorting you are reading the whole history to memory first,
and so it gets slow on big repositories. Is it correct?
With that said, and knowing that libgit2sharp v0.22.1 was working instantly with
.Timesorting,does it mean that v0.22.1 was doing the sorting wrong and therefore it was fast,
or does it mean that it was actually more optimized back then?
Could you clarify that @carlosmn @ethomson ?
Here's the updated test case code:
P.S. While looking at this, this issue popped up, not sure if it is related though: libgit2/libgit2#4736
battlmonstr commentedon Feb 18, 2019
Thanks for help to figure this out. The
.Nonecase works with v0.26.0 and I have a decent workaround for.Time, which is to use .None, Take(15 + 100), and Sort by commit date.ethomson commentedon Feb 19, 2019
This is a clever solution; I'd be interested to hear how it works out for you. Please do let us know if you run into problems or if this remains effective.