Skip to content

Large gitignore slows down operations a lot #3668

Closed

Description

@lacostej

The way git LFS manages its filtering mechanisms in relation to the gitignore file slows down operations a lot.

E.g. an amend to a commit touching a single small file takes 4 seconds with a 800 lines .gitignore and 6 seconds with a 1200 lines file.

Our repo has 30k files, of which 5k are LFS + 7k ignored files and a large gitignore file (~1000 lines).

Tracing reveals that most of the time is spent rejecting / accepting files

$ GIT_TRACE=1 git commit -m "XXX" --amend 2>&1 | tee git.log
$ grep accepting git.log | head -1
08:51:25.676481 trace git-lfs: filepathfilter: accepting "AAAA"
$ grep accepting git.log | tail -1
08:51:31.910054 trace git-lfs: filepathfilter: accepting "BBBB"

(6 seconds between the first and last filepathfilter operations)

Some reading of the code makes me think there's a sub-optimal implementation of Walk() with regard to large gitignores.

git-lfs/tools/filetools.go

Lines 338 to 401 in 06a0c38

func (w *fastWalker) Walk(isRoot bool, workDir string, itemFi os.FileInfo,
excludePaths []filepathfilter.Pattern) {
var fullPath string // Absolute path to the current file or dir
var parentWorkDir string // Absolute path to the workDir inside the repository
if isRoot {
fullPath = w.rootDir
} else {
parentWorkDir = join(w.rootDir, workDir)
fullPath = join(parentWorkDir, itemFi.Name())
}
workPath := join(workDir, itemFi.Name())
if !filepathfilter.NewFromPatterns(nil, excludePaths).Allows(workPath) {
return
}
w.ch <- fastWalkInfo{ParentDir: parentWorkDir, Info: itemFi}
if !itemFi.IsDir() {
// Nothing more to do if this is not a dir
return
}
var childWorkDir string
if !isRoot {
childWorkDir = join(workDir, itemFi.Name())
}
if len(w.excludeFilename) > 0 {
possibleExcludeFile := join(fullPath, w.excludeFilename)
var err error
excludePaths, err = loadExcludeFilename(possibleExcludeFile, childWorkDir, excludePaths)
if err != nil {
w.ch <- fastWalkInfo{Err: err}
}
}
// The absolute optimal way to scan would be File.Readdirnames but we
// still need the Stat() to know whether something is a dir, so use
// File.Readdir instead. Means we can provide os.FileInfo to callers like
// filepath.Walk as a bonus.
df, err := os.Open(fullPath)
if err != nil {
w.ch <- fastWalkInfo{Err: err}
return
}
// The number of items in a dir we process in each goroutine
jobSize := 100
for children, err := df.Readdir(jobSize); err == nil; children, err = df.Readdir(jobSize) {
// Parallelise all dirs, and chop large dirs into batches
w.walk(children, func(subitems []os.FileInfo) {
for _, childFi := range subitems {
w.Walk(false, childWorkDir, childFi, excludePaths)
}
})
}
df.Close()
if err != nil && err != io.EOF {
w.ch <- fastWalkInfo{Err: err}
}
}

Activity

  1. bk2204 commented on May 28, 2019

    @bk2204
    Member

    Hey, thanks for writing in.

    I expect there are definitely some optimizations we could make in this area. Git, for example, has optimizations to check if the item is a directory and ignore items which are not. I think there's been some work on improving some of our correctness which may help us improve performance here as well, by enabling some of the same optimizations that Git has.

    I'll flag this as an enhancement and see if I can get around to looking at it.

  2. jerick1976 commented on Sep 10, 2019

    @jerick1976

    Just wanted to give this issue a bit of a bump. We have a number of large Git repositories with thousands of git-lfs objects that are slowing down on push due to the pre-push scan operations that git-lfs is doing. One of the worst is a repository with 20k git-lfs objects that is using .gitignore files. That repo recently required one hour to push three new binaries that were relatively small.

  3. bk2204 commented on Oct 1, 2019

    @bk2204
    Member

    I believe this has been fixed by #3823.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions