upload-pack: skip parse-object re-hashing of "want" objects

Imagine we have a history with commit C pointing to a large blob B.
If a client asks us for C, we can generally serve both objects to them
without accessing the uncompressed contents of B. In upload-pack, we
figure out which commits we have and what the client has, and feed those
tips to pack-objects. In pack-objects, we traverse the commits and trees
(or use bitmaps!) to find the set of objects needed, but we never open
up B. When we serve it to the client, we can often pass the compressed
bytes directly from the on-disk packfile over the wire.

But if a client asks us directly for B, perhaps because they are doing
an on-demand fetch to fill in the missing blob of a partial clone, we
end up much slower. Upload-pack calls parse_object() on the oid we
receive, which opens up the object and re-checks its hash (even though
if it were a commit, we might skip this parse entirely in favor of the
commit graph!). And then we feed the oid directly to pack-objects, which
again calls parse_object() and opens the object. And then finally, when
we write out the result, we may send bytes straight from disk, but only
after having unnecessarily uncompressed and computed the sha1 of the
object twice!

This patch teaches both code paths to use the new SKIP_HASH_CHECK flag
for parse_object(). You can see the speed-up in p5600, which does a
blob:none clone followed by a checkout. The savings for git.git are
modest:

  Test                          HEAD^             HEAD
  ----------------------------------------------------------------------
  5600.3: checkout of result    2.23(4.19+0.24)   1.72(3.79+0.18) -22.9%

But the savings scale with the number of bytes. So on a repository like
linux.git with more files, we see more improvement (in both absolute and
relative numbers):

  Test                          HEAD^                HEAD
  ----------------------------------------------------------------------------
  5600.3: checkout of result    51.62(77.26+2.76)    34.86(61.41+2.63) -32.5%

And here's an even more extreme case. This is the android gradle-plugin
repository, whose tip checkout has ~3.7GB of files:

  Test                          HEAD^               HEAD
  --------------------------------------------------------------------------
  5600.3: checkout of result    79.51(90.84+5.55)   40.28(51.88+5.67) -49.3%

Keep in mind that these timings are of the whole checkout operation. So
they count the client indexing the pack and actually writing out the
files. If we want to see just the server's view, we can hack up the
GIT_TRACE_PACKET output from those operations and replay it via
upload-pack. For the gradle example, that gives me:

  Benchmark 1: GIT_PROTOCOL=version=2 git.old upload-pack ../gradle-plugin <input
    Time (mean ± σ):     50.884 s ±  0.239 s    [User: 51.450 s, System: 1.726 s]
    Range (min … max):   50.608 s … 51.025 s    3 runs

  Benchmark 2: GIT_PROTOCOL=version=2 git.new upload-pack ../gradle-plugin <input
    Time (mean ± σ):      9.728 s ±  0.112 s    [User: 10.466 s, System: 1.535 s]
    Range (min … max):    9.618 s …  9.842 s    3 runs

  Summary
    'GIT_PROTOCOL=version=2 git.new upload-pack ../gradle-plugin <input' ran
      5.23 ± 0.07 times faster than 'GIT_PROTOCOL=version=2 git.old upload-pack ../gradle-plugin <input'

So a server would see an 80% reduction in CPU serving the initial
checkout of a partial clone for this repository. Or possibly even more
depending on the packing; most of the time spent in the faster one were
objects we had to open during the write phase.

In both cases skipping the extra hashing on the server should be pretty
safe. The client doesn't trust the server anyway, so it will re-hash all
of the objects via index-pack. There is one thing to note, though: the
change in get_reference() affects not just pack-objects, but rev-list,
git-log, etc. We could use a flag to limit to index-pack here, but we
may already skip hash checks in this instance. For commits, we'd skip
anything we load via the commit-graph. And while before this commit we
would check a blob fed directly to rev-list on the command-line, we'd
skip checking that same blob if we found it by traversing a tree.

The exception for both is if --verify-objects is used. In that case,
we'll skip this optimization, and the new test makes sure we do this
correctly.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 files changed
tree: 363356a586ed54b595f2ad11a58bd35f4243e0ff
  1. .github/
  2. block-sha1/
  3. builtin/
  4. ci/
  5. compat/
  6. contrib/
  7. Documentation/
  8. ewah/
  9. git-gui/
  10. gitk-git/
  11. gitweb/
  12. mergetools/
  13. negotiator/
  14. perl/
  15. po/
  16. ppc/
  17. refs/
  18. reftable/
  19. sha1dc/
  20. sha256/
  21. t/
  22. templates/
  23. trace2/
  24. xdiff/
  25. .cirrus.yml
  26. .clang-format
  27. .editorconfig
  28. .gitattributes
  29. .gitignore
  30. .gitmodules
  31. .mailmap
  32. .tsan-suppressions
  33. abspath.c
  34. aclocal.m4
  35. add-interactive.c
  36. add-interactive.h
  37. add-patch.c
  38. advice.c
  39. advice.h
  40. alias.c
  41. alias.h
  42. alloc.c
  43. alloc.h
  44. apply.c
  45. apply.h
  46. archive-tar.c
  47. archive-zip.c
  48. archive.c
  49. archive.h
  50. attr.c
  51. attr.h
  52. banned.h
  53. base85.c
  54. bisect.c
  55. bisect.h
  56. blame.c
  57. blame.h
  58. blob.c
  59. blob.h
  60. bloom.c
  61. bloom.h
  62. branch.c
  63. branch.h
  64. builtin.h
  65. bulk-checkin.c
  66. bulk-checkin.h
  67. bundle-uri.c
  68. bundle-uri.h
  69. bundle.c
  70. bundle.h
  71. cache-tree.c
  72. cache-tree.h
  73. cache.h
  74. cbtree.c
  75. cbtree.h
  76. chdir-notify.c
  77. chdir-notify.h
  78. check-builtins.sh
  79. checkout.c
  80. checkout.h
  81. chunk-format.c
  82. chunk-format.h
  83. CODE_OF_CONDUCT.md
  84. color.c
  85. color.h
  86. column.c
  87. column.h
  88. combine-diff.c
  89. command-list.txt
  90. commit-graph.c
  91. commit-graph.h
  92. commit-reach.c
  93. commit-reach.h
  94. commit-slab-decl.h
  95. commit-slab-impl.h
  96. commit-slab.h
  97. commit.c
  98. commit.h
  99. common-main.c
  100. config.c
  101. config.h
  102. config.mak.dev
  103. config.mak.in
  104. config.mak.uname
  105. configure.ac
  106. connect.c
  107. connect.h
  108. connected.c
  109. connected.h
  110. convert.c
  111. convert.h
  112. copy.c
  113. COPYING
  114. credential.c
  115. credential.h
  116. csum-file.c
  117. csum-file.h
  118. ctype.c
  119. daemon.c
  120. date.c
  121. date.h
  122. decorate.c
  123. decorate.h
  124. delta-islands.c
  125. delta-islands.h
  126. delta.h
  127. detect-compiler
  128. diagnose.c
  129. diagnose.h
  130. diff-delta.c
  131. diff-lib.c
  132. diff-merges.c
  133. diff-merges.h
  134. diff-no-index.c
  135. diff.c
  136. diff.h
  137. diffcore-break.c
  138. diffcore-delta.c
  139. diffcore-order.c
  140. diffcore-pickaxe.c
  141. diffcore-rename.c
  142. diffcore-rotate.c
  143. diffcore.h
  144. dir-iterator.c
  145. dir-iterator.h
  146. dir.c
  147. dir.h
  148. editor.c
  149. entry.c
  150. entry.h
  151. environment.c
  152. environment.h
  153. exec-cmd.c
  154. exec-cmd.h
  155. fetch-negotiator.c
  156. fetch-negotiator.h
  157. fetch-pack.c
  158. fetch-pack.h
  159. fmt-merge-msg.c
  160. fmt-merge-msg.h
  161. fsck.c
  162. fsck.h
  163. fsmonitor--daemon.h
  164. fsmonitor-ipc.c
  165. fsmonitor-ipc.h
  166. fsmonitor-settings.c
  167. fsmonitor-settings.h
  168. fsmonitor.c
  169. fsmonitor.h
  170. fuzz-commit-graph.c
  171. fuzz-pack-headers.c
  172. fuzz-pack-idx.c
  173. generate-cmdlist.sh
  174. generate-configlist.sh
  175. generate-hooklist.sh
  176. gettext.c
  177. gettext.h
  178. git-add--interactive.perl
  179. git-archimport.perl
  180. git-bisect.sh
  181. git-compat-util.h
  182. git-curl-compat.h
  183. git-cvsexportcommit.perl
  184. git-cvsimport.perl
  185. git-cvsserver.perl
  186. git-difftool--helper.sh
  187. git-filter-branch.sh
  188. git-instaweb.sh
  189. git-merge-octopus.sh
  190. git-merge-one-file.sh
  191. git-merge-resolve.sh
  192. git-mergetool--lib.sh
  193. git-mergetool.sh
  194. git-p4.py
  195. git-quiltimport.sh
  196. git-request-pull.sh
  197. git-send-email.perl
  198. git-sh-i18n.sh
  199. git-sh-setup.sh
  200. git-submodule.sh
  201. git-svn.perl
  202. GIT-VERSION-GEN
  203. git-web--browse.sh
  204. git.c
  205. git.rc
  206. gpg-interface.c
  207. gpg-interface.h
  208. graph.c
  209. graph.h
  210. grep.c
  211. grep.h
  212. hash-lookup.c
  213. hash-lookup.h
  214. hash.h
  215. hashmap.c
  216. hashmap.h
  217. help.c
  218. help.h
  219. hex.c
  220. hook.c
  221. hook.h
  222. http-backend.c
  223. http-fetch.c
  224. http-push.c
  225. http-walker.c
  226. http.c
  227. http.h
  228. ident.c
  229. imap-send.c
  230. INSTALL
  231. iterator.h
  232. json-writer.c
  233. json-writer.h
  234. khash.h
  235. kwset.c
  236. kwset.h
  237. levenshtein.c
  238. levenshtein.h
  239. LGPL-2.1
  240. line-log.c
  241. line-log.h
  242. line-range.c
  243. line-range.h
  244. linear-assignment.c
  245. linear-assignment.h
  246. list-objects-filter-options.c
  247. list-objects-filter-options.h
  248. list-objects-filter.c
  249. list-objects-filter.h
  250. list-objects.c
  251. list-objects.h
  252. list.h
  253. ll-merge.c
  254. ll-merge.h
  255. lockfile.c
  256. lockfile.h
  257. log-tree.c
  258. log-tree.h
  259. ls-refs.c
  260. ls-refs.h
  261. mailinfo.c
  262. mailinfo.h
  263. mailmap.c
  264. mailmap.h
  265. Makefile
  266. match-trees.c
  267. mem-pool.c
  268. mem-pool.h
  269. merge-blobs.c
  270. merge-blobs.h
  271. merge-ort-wrappers.c
  272. merge-ort-wrappers.h
  273. merge-ort.c
  274. merge-ort.h
  275. merge-recursive.c
  276. merge-recursive.h
  277. merge.c
  278. mergesort.h
  279. midx.c
  280. midx.h
  281. name-hash.c
  282. notes-cache.c
  283. notes-cache.h
  284. notes-merge.c
  285. notes-merge.h
  286. notes-utils.c
  287. notes-utils.h
  288. notes.c
  289. notes.h
  290. object-file.c
  291. object-name.c
  292. object-store.h
  293. object.c
  294. object.h
  295. oid-array.c
  296. oid-array.h
  297. oidmap.c
  298. oidmap.h
  299. oidset.c
  300. oidset.h
  301. oidtree.c
  302. oidtree.h
  303. pack-bitmap-write.c
  304. pack-bitmap.c
  305. pack-bitmap.h
  306. pack-check.c
  307. pack-mtimes.c
  308. pack-mtimes.h
  309. pack-objects.c
  310. pack-objects.h
  311. pack-revindex.c
  312. pack-revindex.h
  313. pack-write.c
  314. pack.h
  315. packfile.c
  316. packfile.h
  317. pager.c
  318. parallel-checkout.c
  319. parallel-checkout.h
  320. parse-options-cb.c
  321. parse-options.c
  322. parse-options.h
  323. patch-delta.c
  324. patch-ids.c
  325. patch-ids.h
  326. path.c
  327. path.h
  328. pathspec.c
  329. pathspec.h
  330. pkt-line.c
  331. pkt-line.h
  332. preload-index.c
  333. pretty.c
  334. pretty.h
  335. prio-queue.c
  336. prio-queue.h
  337. progress.c
  338. progress.h
  339. promisor-remote.c
  340. promisor-remote.h
  341. prompt.c
  342. prompt.h
  343. protocol-caps.c
  344. protocol-caps.h
  345. protocol.c
  346. protocol.h
  347. prune-packed.c
  348. prune-packed.h
  349. quote.c
  350. quote.h
  351. range-diff.c
  352. range-diff.h
  353. reachable.c
  354. reachable.h
  355. read-cache.c
  356. README.md
  357. rebase-interactive.c
  358. rebase-interactive.h
  359. rebase.c
  360. rebase.h
  361. ref-filter.c
  362. ref-filter.h
  363. reflog-walk.c
  364. reflog-walk.h
  365. reflog.c
  366. reflog.h
  367. refs.c
  368. refs.h
  369. refspec.c
  370. refspec.h
  371. remote-curl.c
  372. remote.c
  373. remote.h
  374. replace-object.c
  375. replace-object.h
  376. repo-settings.c
  377. repository.c
  378. repository.h
  379. rerere.c
  380. rerere.h
  381. reset.c
  382. reset.h
  383. resolve-undo.c
  384. resolve-undo.h
  385. revision.c
  386. revision.h
  387. run-command.c
  388. run-command.h
  389. SECURITY.md
  390. send-pack.c
  391. send-pack.h
  392. sequencer.c
  393. sequencer.h
  394. serve.c
  395. serve.h
  396. server-info.c
  397. setup.c
  398. sh-i18n--envsubst.c
  399. sha1dc_git.c
  400. sha1dc_git.h
  401. shallow.c
  402. shallow.h
  403. shared.mak
  404. shell.c
  405. shortlog.h
  406. sideband.c
  407. sideband.h
  408. sigchain.c
  409. sigchain.h
  410. simple-ipc.h
  411. sparse-index.c
  412. sparse-index.h
  413. split-index.c
  414. split-index.h
  415. stable-qsort.c
  416. strbuf.c
  417. strbuf.h
  418. streaming.c
  419. streaming.h
  420. string-list.c
  421. string-list.h
  422. strmap.c
  423. strmap.h
  424. strvec.c
  425. strvec.h
  426. sub-process.c
  427. sub-process.h
  428. submodule-config.c
  429. submodule-config.h
  430. submodule.c
  431. submodule.h
  432. symlinks.c
  433. tag.c
  434. tag.h
  435. tar.h
  436. tempfile.c
  437. tempfile.h
  438. thread-utils.c
  439. thread-utils.h
  440. tmp-objdir.c
  441. tmp-objdir.h
  442. trace.c
  443. trace.h
  444. trace2.c
  445. trace2.h
  446. trailer.c
  447. trailer.h
  448. transport-helper.c
  449. transport-internal.h
  450. transport.c
  451. transport.h
  452. tree-diff.c
  453. tree-walk.c
  454. tree-walk.h
  455. tree.c
  456. tree.h
  457. unicode-width.h
  458. unimplemented.sh
  459. unix-socket.c
  460. unix-socket.h
  461. unix-stream-server.c
  462. unix-stream-server.h
  463. unpack-trees.c
  464. unpack-trees.h
  465. upload-pack.c
  466. upload-pack.h
  467. url.c
  468. url.h
  469. urlmatch.c
  470. urlmatch.h
  471. usage.c
  472. userdiff.c
  473. userdiff.h
  474. utf8.c
  475. utf8.h
  476. varint.c
  477. varint.h
  478. version.c
  479. version.h
  480. versioncmp.c
  481. walker.c
  482. walker.h
  483. wildmatch.c
  484. wildmatch.h
  485. worktree.c
  486. worktree.h
  487. wrap-for-bin.sh
  488. wrapper.c
  489. write-or-die.c
  490. ws.c
  491. wt-status.c
  492. wt-status.h
  493. xdiff-interface.c
  494. xdiff-interface.h
  495. zlib.c
README.md

Build status

Git - fast, scalable, distributed revision control system

Git is a fast, scalable, distributed revision control system with an unusually rich command set that provides both high-level operations and full access to internals.

Git is an Open Source project covered by the GNU General Public License version 2 (some parts of it are under different licenses, compatible with the GPLv2). It was originally written by Linus Torvalds with help of a group of hackers around the net.

Please read the file INSTALL for installation instructions.

Many Git online resources are accessible from https://git-scm.com/ including full documentation and Git related tools.

See Documentation/gittutorial.txt to get started, then see Documentation/giteveryday.txt for a useful minimum set of commands, and Documentation/git-<commandname>.txt for documentation of each command. If git has been correctly installed, then the tutorial can also be read with man gittutorial or git help tutorial, and the documentation of each command with man git-<commandname> or git help <commandname>.

CVS users may also want to read Documentation/gitcvs-migration.txt (man gitcvs-migration or git help cvs-migration if git is installed).

The user discussion and development of Git take place on the Git mailing list -- everyone is welcome to post bug reports, feature requests, comments and patches to git@vger.kernel.org (read Documentation/SubmittingPatches for instructions on patch submission and Documentation/CodingGuidelines).

Those wishing to help with error message, usage and informational message string translations (localization l10) should see po/README.md (a po file is a Portable Object file that holds the translations).

To subscribe to the list, send an email with just “subscribe git” in the body to majordomo@vger.kernel.org (not the Git list). The mailing list archives are available at https://lore.kernel.org/git/, http://marc.info/?l=git and other archival sites.

Issues which are security relevant should be disclosed privately to the Git Security mailing list git-security@googlegroups.com.

The maintainer frequently sends the “What's cooking” reports that list the current status of various development topics to the mailing list. The discussion following them give a good reference for project status, development direction and remaining tasks.

The name “git” was given by Linus Torvalds when he wrote the very first version. He described the tool as “the stupid content tracker” and the name as (depending on your mood):

  • random three-letter combination that is pronounceable, and not actually used by any common UNIX command. The fact that it is a mispronunciation of “get” may or may not be relevant.
  • stupid. contemptible and despicable. simple. Take your pick from the dictionary of slang.
  • “global information tracker”: you're in a good mood, and it actually works for you. Angels sing, and a light suddenly fills the room.
  • “goddamn idiotic truckload of sh*t”: when it breaks