Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git index and commit is very slow

Tags:

git

I have a local git repository and use git add file1 file2 file3... to add my modifications to the git index. Afterwards I use a plain git commit. Each command takes around 3 to 6 seconds. My repository has around 150.000 commits.

I already executed git gc since I assumed it would perform some garbage collection. The SSD is quite fast. I am wondering which screws I can turn in git to accelerate the execution of these two commands. Any advice?

git version 2.21.0 (Apple Git-122.2)

My system is a Mac Pro with MacOS 10.14.6. I use a SSD with APFS. No anti virus software (or any other interfering scanning software) is installed.

like image 885
Daniel Stephens Avatar asked Jan 19 '20 17:01

Daniel Stephens


Video Answer


1 Answers

First, update to the latest Git 2.25: performance issues are resolved with each new version.

To investigate performance issues, set the GIT_TRACE2_PERF environment variable to 1 and run the git command. See this SO answer for details about the trace2 feature and how to interpret the output table.

(In Bash you can set a variable and run a command in the same line)

GIT_TRACE2_PERF=1 git commit -m "test"

In Windows command-prompt, you'll need to use SET:

SET GIT_TRACE2_PERF=1
git commit -m "test"

Or, in a CMD in one line:

cmd /V /C "SET "GIT_TRACE2_PERF=1" && git commit -m "test""

For example, on Windows, you'll see output that looks like this:

C:\git\me\foobar>SET GIT_TRACE2_PERF=1

C:\git\me\foobar>git status
17:23:13.056175 common-main.c:48             | d0 | main                     | version      |     |           |           |              | 2.31.1.windows.1
17:23:13.056175 common-main.c:49             | d0 | main                     | start        |     |  0.003356 |           |              | git.exe status
17:23:13.065174 ..._win32_process_info.c:118 | d0 | main                     | data_json    | r0  |  0.012053 |  0.012053 | process      | windows/ancestry:["git.exe","cmd.exe","explorer.exe"]
17:23:13.066174 repository.c:130             | d0 | main                     | def_repo     | r1  |           |           |              | worktree:C:/git/me/foobar
17:23:13.067174 git.c:448                    | d0 | main                     | cmd_name     |     |           |           |              | status (status)
17:23:13.068174 read-cache.c:2324            | d0 | main                     | region_enter | r1  |  0.015462 |           | index        | label:do_read_index .git/index
17:23:13.069175 cache-tree.c:598             | d0 | main                     | region_enter | r1  |  0.015809 |           | cache_tree   | ..label:read
17:23:13.069175 cache-tree.c:600             | d0 | main                     | region_leave | r1  |  0.016021 |  0.000212 | cache_tree   | ..label:read
17:23:13.069175 read-cache.c:2284            | d0 | main                     | data         | r1  |  0.016056 |  0.000594 | index        | ..read/version:2
17:23:13.069175 read-cache.c:2286            | d0 | main                     | data         | r1  |  0.016065 |  0.000603 | index        | ..read/cache_nr:3808
17:23:13.069175 read-cache.c:2329            | d0 | main                     | region_leave | r1  |  0.016072 |  0.000610 | index        | label:do_read_index .git/index

Note the wall-clock times in the leftmost column, total time since start in the 7th column, and total time for each sub-operation in the 8th column.

like image 78
VonC Avatar answered Oct 21 '22 07:10

VonC