Skip to content

Opt-in to Git protocol v2 for better perf when fetching references

Administrator requested to merge gitprotocolv2 into master

Created by: nicksnyder

We were aware of this last year, but it seems like we misinterpreted the blog post and thought that all we needed to do is update our version of git.

Taking advantage of the protocol does require setting a config option on the client to opt-in.

To demonstrate the difference, I started a fresh 3.6 instance of Sourcegraph (single docker image) and ran a git fetch with and without -c protocol.version=2.

Using protocol v2 significantly reduces the size of the data fetched from the server.

$ docker exec -it 8db280883c5f /bin/sh

/ # git version
git version 2.22.0

/ # git clone https://github.com/sourcegraph/sourcegraph
Cloning into 'sourcegraph'...
remote: Enumerating objects: 1343, done.
remote: Counting objects: 100% (1343/1343), done.
remote: Compressing objects: 100% (1065/1065), done.
remote: Total 357117 (delta 294), reused 591 (delta 222), pack-reused 355774
Receiving objects: 100% (357117/357117), 305.94 MiB | 9.96 MiB/s, done.
Resolving deltas: 100% (244206/244206), done.
/ # export GIT_TRACE_PACKET=1
/ # cd sourcegraph/
/sourcegraph # git fetch --no-tags origin master 2>&1 | wc -l
3391
/sourcegraph # git -c protocol.version=2 fetch --no-tags origin master 2>&1 | wc -l
44

Ideally we would set this in the global git config on gitserver on the off chance there are other code paths in the future, but this seems like the simplest change to make now.

cc @ggilmore since this could be related to https://sourcegraph.slack.com/archives/CLZ3BK0Q6/p1565217996012700

Merge request reports

Loading