7

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.

Daniel Stephens
  • 1,649
  • 6
  • 23
  • 59
  • The number of commits shouldn't make a difference, but the number of files being changed might. How many files are you adding? Do both `git add` and `git commit` take 3 to 6 seconds, or is it just `git commit`? Are other commends like `git log` or `git diff` also very slow? – Schwern Jan 19 '20 at 20:01
  • 2
    You can run `GIT_TRACE_PERFORMANCE=1 git ` to see where Git spends its time. – Henri Menke Jan 19 '20 at 22:05
  • And also update git because each version introduced perf improvements especially for big repositories... – Philippe Jan 19 '20 at 22:36
  • 1
    What sort of files are you adding? Git will compress objects using zlib whenever you make a commit, and if your files are binary objects then this compression is going to burn some CPU cyles. For this reason git really should only be used with text files. If you're adding binary objects like images, media, application binaries/archives etc, you should use git-lfs so that git can store these objects uncompressed in a separate location. – daveruinseverything Jan 20 '20 at 00:42

1 Answers1

7

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.

VonC
  • 1,129,465
  • 480
  • 4,036
  • 4,755