You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Benchmark the different options and see whether they are natively doable with libgit
Depending on the results of the above
Go the treeless route if reasonably fast and supported
Always eagerly fetch all commit history (the "spine")
roberth: Doesn't have to be eager, but eager is easier to implement for now
Always fetch just one tree
revCount supported because have commit history
cannot fetch from shallow repo trivially, but ways around this
users encouraged to likewise do treeless clones locally rather than traditional shallow to not hit this restriction.
Open Questions:
can libgit do treeless clones? (otherwise we can shell out)? Is libgit open to adding such functionality?
Can libgit manage/manipulate a treeless clone?
Continue to have fetching all the history be conditional.
Optional (because needed for revCount)
Default for fetchTree is norevCount, but for fetchGit for backwards-compat we have to keep revCount by default.
@tomberek: not fetching all the history means to use "shallow = true" / --depth 1
(later) consider using that for fetchFromGithub and friends if the performance is good enough
With either version of (2) we never need to fetch any trees of other commits. The only question is whether we fetch all the commits and support revCount.
Collect data to decide if fetching the git history can be optimized so that it becomes viable to have this as the only strategy for fetching git repos, or if it is better to make fetching history conditional via a flag.
The two variants that are raced against each other in this benchmark:
Variant 1: Fetch only the tree (the files) of a single given revision
Variant 2: Like Variant 1 but also fetch the commit history (treeless), in order to be able to return revCount.
Using the git cli tool:
Variant 1 requires 1 invocation:
fetch tree
Variant 2 requires 3 invocations:
fetch tree
fetch commits
compute rev-count
Setup of the benchmark
Repo: nixpkgs
Remotes:
github
gitlab
bitbucket
gitea
Tested operations (measured in seconds):
Fetch tree
Fetch commits
Compute rev-count
Test Machines:
cloud VM
notebook + 5G hotspot
Measured properties
tree seconds: Seconds it took to fetch the tree shallowly
commit seconds: Seconds it took to fetch the commit history treeless
rev-count seconds: Seconds it took to compute the revision count
Computed properties
total duration: Sum of all 3 steps
slowdown factor: Total fetching time of Variant 2 relative to Variant 1
Fetching the commit history in an optimized way requires using a --filter for git fetch. Bitbucket, which was one of the tested providers does not support filtering, therefore git falls back to full cloning, leading to very bad performance just for getting the rev-count.
Overhead of Variant 2 is significant
Even in the best cases, fetching the commit history slows down the fetching by at least a factor of 3.7.
For example, from a cloud VM fetching a nixpkgs revision from github takes 8 seconds, while fetching the commit history and computing the revCount takes an additional 24 seconds, which is a slowdown by factor of 4.
In the case of nixpkgs, the number of objects that need to be fetched for the history is far larger than the number of tree objects for a single revision. It's ~500k objects for the history vs. ~60k for the tree.
Inconsistent overhead of Variant 2
While fetching the tree gives relatively consistent results, fetching the commit history is fast on some runs, but much slower on others, even for the same provider. This was only experienced with github on the 5G connection, and not from within the cloud. It might be an outlier, but it might be possible that github doesn't serve all kinds of requests with the same priority.
Opinion
My opinion after these observations is that we should go with approach 2/ii from above, meaning the history fetching becomes optional and with it the revCount attribute as well.
Always fetching the history eagerly as described in 2/i would impose:
significant slowdown (at least 3.7x slower for nixpkgs, adding at least 22s)
and either:
relying on servers to support filtering
or fetching the full history which performs much worse (40x slower for nixpkgs)
Add a shallowRev = true/false argument to fetchTree which is false by default in fetchTree and true by default in fetchGit. (I think it is useful for this flag to have shallow in its name, because that is what people will most likely search for in manuals).
Add support for submodules
Investigate if caching shallow repos provides any benefit
Add caching or not
Investigate filtering support of libgit2
Add filtering to reduce the overhead when fetching the commit history in case shallowRev = true.
After the nix team adopts and/or confirms the plan, I can start working on it.
EDIT: an alternative plan could be to first optimize the current case, which means adding filtering support for the commit history right away. If libgit2 supports this, then this might be easy to do and it already provides quite a significant performance gain in many cases.
Pursuing 2.ii seems to be the right call indeed given your benchmarks (I didn't know about --unshallow, that's pretty neat btw).
The roadmap makes sense too, although I wouldn't be too strict about the ordering of the steps (different people will probably have different priorities here).
I'm not sure about the shallowRev name (at least it doesn't mean much to me), but that can be a separate dicsussion.
Activity
[-]Shallowness fetch of git fetching[/-][+]Shallowness of git fetching[/+]nixos-discourse commentedon Nov 23, 2023
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/2023-11-20-nix-team-meeting-minutes-105/35902/1
DavHau commentedon Nov 23, 2023
I'll start working on the benchmarks and post here as soon as I have some results.
DavHau commentedon Nov 30, 2023
Git shallow fetching benchmark
Goals
Collect data to decide if fetching the git history can be optimized so that it becomes viable to have this as the only strategy for fetching git repos, or if it is better to make fetching history conditional via a flag.
The two variants that are raced against each other in this benchmark:
Variant 1but also fetch the commit history (treeless), in order to be able to return revCount.Using the git cli tool:
Variant 1requires 1 invocation:Variant 2requires 3 invocations:Setup of the benchmark
Repo: nixpkgs
Remotes:
Tested operations (measured in seconds):
Test Machines:
Measured properties
Computed properties
Variant 2relative toVariant 1Results
https://docs.google.com/spreadsheets/d/1yLo4XMCKj-4xZVHBz2z4BwxBWI76xjVe7gtNgaNG7co/edit?usp=sharing
Reproduce
nix build github:DavHau/nix-git-research#benchmark-fod -LObservations
Support for commit fetching varies
Fetching the commit history in an optimized way requires using a
--filterforgit fetch. Bitbucket, which was one of the tested providers does not support filtering, therefore git falls back to full cloning, leading to very bad performance just for getting the rev-count.Overhead of Variant 2 is significant
Even in the best cases, fetching the commit history slows down the fetching by at least a factor of 3.7.
For example, from a cloud VM fetching a nixpkgs revision from github takes 8 seconds, while fetching the commit history and computing the revCount takes an additional 24 seconds, which is a slowdown by factor of 4.
In the case of nixpkgs, the number of objects that need to be fetched for the history is far larger than the number of tree objects for a single revision. It's ~500k objects for the history vs. ~60k for the tree.
Inconsistent overhead of Variant 2
While fetching the tree gives relatively consistent results, fetching the commit history is fast on some runs, but much slower on others, even for the same provider. This was only experienced with github on the 5G connection, and not from within the cloud. It might be an outlier, but it might be possible that github doesn't serve all kinds of requests with the same priority.
Opinion
My opinion after these observations is that we should go with approach 2/ii from above, meaning the history fetching becomes optional and with it the revCount attribute as well.
Always fetching the history eagerly as described in 2/i would impose:
Roadmap Proposal
shallowRev = true/falseargument to fetchTree which isfalseby default in fetchTree andtrueby default in fetchGit. (I think it is useful for this flag to haveshallowin its name, because that is what people will most likely search for in manuals).shallowRev = true.After the nix team adopts and/or confirms the plan, I can start working on it.
EDIT: an alternative plan could be to first optimize the current case, which means adding filtering support for the commit history right away. If libgit2 supports this, then this might be easy to do and it already provides quite a significant performance gain in many cases.
thufschmitt commentedon Nov 30, 2023
Thanks for the detailed analysis @DavHau !
Pursuing 2.ii seems to be the right call indeed given your benchmarks (I didn't know about
--unshallow, that's pretty neat btw).The roadmap makes sense too, although I wouldn't be too strict about the ordering of the steps (different people will probably have different priorities here).
I'm not sure about the
shallowRevname (at least it doesn't mean much to me), but that can be a separate dicsussion.DavHau commentedon Dec 24, 2023
I was on holiday and will pick this up now.
nixos-discourse commentedon Jan 12, 2024
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/2023-12-15-nix-team-meeting-minutes-112/38155/1
hugosenari commentedon Oct 11, 2025
This was resolved by #10028 ?
ZoomRmc commentedon Oct 11, 2025
fetchTreecan perform shallow fetches,fetchGitcannot still.xokdvium commentedon Oct 11, 2025
Did you mean to say it doesn't do it by default? Because it very much can do shallow clones https://nix.dev/manual/nix/2.32/language/builtins.html?highlight=fetchGit#builtins-fetchGit, but changing the default of
fetchGitbuiltin would be a breaking change and thus can't be done.DavHau commentedon Oct 15, 2025
I twas reverted via #11172