Skip to content

git-lfs is unusable slow (especially on Windows) #376

Closed

Description

@bozaro

I convert my repository to git-lfs and try to make simple checkout:

  • Linux: 1436 sec
  • Windows: 4970 sec

Git repository is accessible by ssh protocol. LFS-server is defined by simple git-lfs-authenticate script:

#!/bin/sh
echo '{
  "href": "http://git.test.local:9999/test/test",
  "header": {
    "Authorization": "Basic dGVzdDp0ZXN0"
  }
}'

The main performance issues:

  • git-lfs for every file establish new ssh connection and executes git-lfs-authenticate command (aditional ~0.3 sec per file on Windows, ~0.2 sec per file on Linux);
  • git-lfs for every file executed as separate process (additional ~0.2 sec per file on Windows);

It should be noted that in the case of:

  • if the git-lfs-authenticate knows how files are stored, then he could immediately return the "download" section and save one HTTP request;
  • if the git-lfs-authenticate don't knows how files are stored, it always returns the same result.

In addition, processing each file in a separate process does not allow reusing HTTP connections.

Working copy contains 4231 LFS files (total size: 3.6G).
All data hosted in local gigabit network. I am sure that in the case of slower network results will be much sadder.

Versions:

  • Windows test:
    • Windows 8.1
    • git-lfs: 0.5.1
    • git: 1.9.5.msysgit.1
    • ssh: OpenSSH_6.6p1, OpenSSL 1.0.1f 6 Jan 2014
  • Linux test
    • Ubuntu 14.04.2 LTS
    • git-lfs: 0.5.1
    • git: 1.9.1
    • ssh: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2, OpenSSL 1.0.1f 6 Jan 2014

Activity

  1. bozaro commented on Jun 10, 2015

    @bozaro
    ContributorAuthor

    Also performance on Windows can be improvement by changing in .gitconfig:

    From:

    [filter "lfs"]
        clean = git lfs clean %f
        smudge = git lfs smudge %f
    

    To:

    [filter "lfs"]
        clean = git-lfs clean %f
        smudge = git-lfs smudge %f
    

    This small change reduce clone time on Windows from 4970 sec to 4352 sec (1.14X faster).

  2. bozaro commented on Jun 10, 2015

    @bozaro
    ContributorAuthor

    I try to use ssh multiplexing as workaround (http://en.wikibooks.org/wiki/OpenSSH/Cookbook/Multiplexing).
    It's reduce clone time on Linux from 1436 sec to 541 sec (2.65X faster).
    But I could not get this feature to work under Windows.

  3. technoweenie commented on Jun 10, 2015

    @technoweenie
    Contributor

    Hey @bozaro, thanks for the feedback. There are several causes of pain here:

    As you mentioned, the smudge filter downloads files one at a time in a separate process. This is how Git works, so the only thing we can do is to not use it ;) The master branch already has an early version of a git lfs fetch command that can download objects in parallel. We plan to investigate using a post-checkout hook to download the files with the new fetch command.

    The core Git LFS API is very chatty, requiring an HTTP call for every upload or download. The master branch already has support for an experimental batch API. This is coupled with the work on the new fetch command.

    We also plan to investigate reducing the number of SSH calls by some in-memory caching made possible by a single fetch command, as opposed to multiple smudge filter calls.

    Also, thanks for #377 :)

  4. bozaro commented on Jun 11, 2015

    @bozaro
    ContributorAuthor

    I got ssh multiplexing to work under Windows :)

    I build git-lfs 0.5.1 with changes: #380 + #377
    After I setup git to use plink with "Share SSH connections if possible" and clone time reduced on Windows to 3561.472 sec.
    It's 1.40X time faster then original time.

  5. AndrewJDR commented on Oct 6, 2015

    @AndrewJDR
    Contributor

    bonzaro, thanks for your notes.
    I'm curious... how long does the following take with your repo (and with batch enabled in your .gitconfig)

    GIT_LFS_SKIP_SMUDGE=1 git clone ...
    cd your_repo && git lfs fetch
    

    enable batch in ~/.gitconifg first:

    [lfs]                                                                                                                                                                                                
    ­­­­­­­batch = true                                                                                                                                                                                 
    ­­­­­­­concurrenttransfers = 12
    
  6. bozaro commented on Oct 6, 2015

    @bozaro
    ContributorAuthor

    At the moment, we have put in git-lfs only a few particularly large files (~80 lfs files in the working copy).

    This half-measure will significantly reduce the size of the repository. But git clone (repository ~8Gb) takes longer than git lfs. Full clone with lfs data now takes 15-20 minutes.

    We would like to use git-lfs for ~5000 working copy files. But with smudge filter it does not look real.

    Using git lfs pull requires the support of our build farm. We have not done it since I was not aware of the environment variable GIT_LFS_SKIP_SMUDGE.

  7. AndrewJDR commented on Oct 6, 2015

    @AndrewJDR
    Contributor

    Ah ok. I think GIT_LFS_SKIP_SMUDGE is only in the current git version?

    You can also do "git clone -n", then do "git lfs fetch origin ", and "git checkout ". I believe this should be similar to using GIT_LFS_SKIP_SMUDGE git clone + git lfs fetch.
    All of this assumes you have batch enabled.

  8. golsby commented on Oct 12, 2015

    @golsby

    We're very new to using git, and we're moving a big project with a large number of big libs into a github private repo. We're setting up submodules with git-lfs for several projects that have 2.2GB of third-party libs. We've named the submodule "big_libs".

    We had exactly the problem described in this thread, and the previous comment helped us a ton for the main repo. Now, I need to do the same thing for the submodule "big_libs".

    I want a series of operations that I can run to make:
    git clone --recursive <repo>

    Fast like:

    git clone -n <repo>
    cd <repo>
    git lfs fetch origin
    git checkout
    

    I tried:

    git clone -n <repo>
    cd <repo>
    git lfs fetch origin
    git checkout
    git submodule init
    git submodule update -N
    

    but the last line gets us back into the one-file-at-a-time git lfs downloads.

    Can I just do:

    git submodule init
    mkdir big_libs
    cd big_libs
    git clone -n https://github.com/mcneel/big_libs.git .
    git lfs fetch origin
    git checkout
    

    And have the submodule be properly cloned by git for future git submodule update calls?

  9. AndrewJDR commented on Oct 13, 2015

    @AndrewJDR
    Contributor

    If you use GIT_LFS_SKIP_SMUDGE=1 in your environment, that should prevent one-at-a-time smudge from happening. Only problem is, I'm not sure GIT_LFS_SKIP_SMUDGE exists in git-lfs 1.0 yet. You may need to build the latest git-lfs from the git repo to get that feature. Maybe one of the devs can chime in to answer definitively though.

  10. AndrewJDR commented on Oct 13, 2015

    @AndrewJDR
    Contributor

    You might also try something like

    git clone -n <repo>
    cd <repo>
    git lfs fetch origin
    git checkout
    git submodule init
    git submodule foreach git lfs fetch origin
    git submodule update
    

    The foreach command should run the lfs fetch in each submodule. If you do that prior to submodule update then you should be all set.

  11. josteinaj commented on Dec 14, 2015

    @josteinaj

    While the GIT_LFS_SKIP_SMUDGE-workaround works great for me since I'm using git from the command line on Linux, it doesn't help my colleagues who use GitHub Desktop on Windows. We have 16354 audio files in git lfs and each one of them takes two or three seconds to retrieve using GitHub Desktop, so it's going to take a whole day (22 hours if we assume 5 seconds per audio file!) to make the initial clone of our repo.

  12. technoweenie commented on Dec 14, 2015

    @technoweenie
    Contributor

    @josteinaj You can work around it for now by cloning from GitHub Desktop's shell manually.

  13. WestonThayer commented on Jan 28, 2016

    @WestonThayer

    @technoweenie could you elaborate on that? You have to use the GitHub Desktop GUI?

  14. technoweenie commented on Feb 1, 2016

    @technoweenie
    Contributor

    GitHub Desktop on Windows bundles git-lfs and provides a "Git Shell" shortcut that loads the proper environment. This lets them access git-lfs from the command line to run custom commands without having to manually install git-lfs separately.

  15. slonopotamus commented on Feb 2, 2016

    @slonopotamus
    Contributor

    The only sane solution for this bug is to add batch smudge filter support to Git itself. All the rest is doomed to be half-crippled workarounds.

  16. AndrewJDR commented on Feb 2, 2016

    @AndrewJDR
    Contributor
  17. WestonThayer commented on Feb 23, 2016

    @WestonThayer

    FYI, for anyone looking for a sane workaround for an extremely slow git clone (and who doesn't want to read through all these issues), try this:

    set GIT_LFS_SKIP_SMUDGE=1
    git clone http://whatever.git
    cd Whatever
    git lfs pull
    

    Note: set GIT_LFS_SKIP_SMUDGE=1 is how you set an environment variable in the Windows command line. Your shell may be different.

    Explanation-in-a-nutshell: git-lfs magically integrates with normal git commands (clone, pull, push, etc) through a git feature called filters. The filters are the bottleneck (they force git-lfs to download each file in serial, plus some other slowness). When you want to download files from the server (e.g. git fetch), the "smudge" filter runs. By setting the GIT_LFS_SKIP_SMUDGE environment variable, you tell git-lfs to skip trying to download files as part of the standard git commands. That frees you to run git lfs pull separately, which by default downloads files in batches of 3 (you can increase this number, but I've found that's fast enough for me). It is way faster.

    Until you either close your command prompt or unset the GIT_LFS_SKIP_SMUDGE variable, this will continue to be the case. Since git clone is guaranteed to be slow (we have to download every file), it makes sense to always do the git lfs pull separately, but for everyday git pull and git push operations, remembering to run the corresponding git-lfs command can be annoying, so we let it work magically by leaving the GIT_LFS_SKIP_SMUDGE variable unset most of the time. You can of course turn it on and off at your leisure.

  18. sinbad commented on Feb 24, 2016

    @sinbad
    Contributor

    From git-lfs 1.2 (or master right now) you can use git lfs clone to speed up clones even more than using GIT_LFS_SKIP_SMUDGE. I'm proposing we add similar options for checkout & pull in future.

  19. AndrewJDR commented on Feb 24, 2016

    @AndrewJDR
    Contributor

    @sinbad - Curious, what makes git lfs clone faster than skipping smudge followed by a subsequent git lfs pull?

  20. sinbad commented on Feb 24, 2016

    @sinbad
    Contributor

    Discussed in more detail in #931 but basically avoiding calling the filter executable at all makes it faster than calling it and then doing nothing like GIT_LFS_SKIP_SMUDGE does, especially on Windows.

  21. sinbad commented on Feb 29, 2016

    @sinbad
    Contributor

    @R-ku The reason is down to how git tries to detect file changes. An in-depth discussion is here: https://www.kernel.org/pub/software/scm/git/docs/technical/racy-git.txt but it boils down to the fact that because of timer precision and fast machines, a simple check of date/time stamps isn't always good enough and when a file goes through a filter like git-lfs does, git can only compare to the index by putting the current contents of the file through the clean filter. In bulk, this can cause an issue sometimes; it's actually worse on files you haven't modified yourself, because when you modify yourself there's often a time delay between the last edit you make, and the time you add/commit. It's worse on clean clones on a fast machine because of the likelihood that a lot of the timestamps will be the same.

    The only workaround I know right now is a bit nasty, and I'd only recommend using it once it's a significant problem for you. You can disable git's checking of files by doing this:

    git update-index --assume-unchanged <path>
    

    Once you do that though, git status will not show changes in those paths; you can still add things to the index in those paths but it won't show up as modified just by saving the file. You can undo this setting with the same command just with --no-assume-unchanged. It's not a great solution but if it's hurting you badly, it's a coping mechanism. Most filter-based systems hit this problem and I haven't so far found a comprehensive solution.

  22. technoweenie commented on Feb 29, 2016

    @technoweenie
    Contributor

    @R-ku Ah yup, I wrote a terrible description of that command :) However, Git's clean filter doesn't overwrite files in your working directory. It reads the file contents through a command before checking for a change and/or writing it to git's object database. The Git LFS clean filter reads the data and outputs the LFS text pointer instead.

  23. sinbad commented on Feb 29, 2016

    @sinbad
    Contributor

    Would it essentially delete all that 12GB of files one by one and place it back just for checking if file did not change?

    No, it just reads the files and converts to a pointer (piped to stdout) which is compared against the index. It doesn't even need to write that converted pointer anywhere on the disk, the comparison can be done by reading the index in parallel (in blocks) and matching. So it's only disk reads, no writes.

  24. sinbad commented on Mar 1, 2016

    @sinbad
    Contributor

    From your first link:

    Update: I tried this again (2015) and it seems that git status and git add avoid re-sending the file content to the clean filter, as long as the file stat has not changed. I'm not sure when git started doing that, but it seems to avoid this problem. --Joey

    This is my experience and GIT_TRACE shows that the clean filter on status is avoided in many cases for me. But the rest of those threads are basically what I was talking about - when the clean filter IS called, either because the time stamps are too close (and this is not 'wrong', it's just a feature of fast file systems and clock precision) the scalability issue is a known, so far unsolved problem, by any of us. git update-index --assume-unchanged is the only workaround I know of right now besides going completely outside git filters and doing it manually, which substantially increases the complexity for the user and hence chance of mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions