pack-revindex: introduce `pack.readReverseIndex`

Since 1615c567b8 (Documentation/config/pack.txt: advertise
'pack.writeReverseIndex', 2021-01-25), we have had the
`pack.writeReverseIndex` configuration option, which tells Git whether
or not it is allowed to write a ".rev" file when indexing a pack.

Introduce a complementary configuration knob, `pack.readReverseIndex` to
control whether or not Git will read any ".rev" file(s) that may be
available on disk.

This option is useful for debugging, as well as disabling the effect of
".rev" files in certain instances.

This is useful because of the trade-off[^1] between the time it takes to
generate a reverse index (slow from scratch, fast when reading an
existing ".rev" file), and the time it takes to access a record (the
opposite).

For example, even though it is faster to use the on-disk reverse index
when computing the on-disk size of a packed object, it is slower to
enumerate the same value for all objects.

Here are a couple of examples from linux.git. When computing the above
for a single object, using the on-disk reverse index is significantly
faster:

    $ git rev-parse HEAD >in
    $ hyperfine -L v false,true 'git.compile -c pack.readReverseIndex={v} cat-file --batch-check="%(objectsize:disk)" <in'
    Benchmark 1: git.compile -c pack.readReverseIndex=false cat-file --batch-check="%(objectsize:disk)" <in
      Time (mean ± σ):     302.5 ms ±  12.5 ms    [User: 258.7 ms, System: 43.6 ms]
      Range (min … max):   291.1 ms … 328.1 ms    10 runs

    Benchmark 2: git.compile -c pack.readReverseIndex=true cat-file --batch-check="%(objectsize:disk)" <in
      Time (mean ± σ):       3.9 ms ±   0.3 ms    [User: 1.6 ms, System: 2.4 ms]
      Range (min … max):     2.0 ms …   4.4 ms    801 runs

    Summary
      'git.compile -c pack.readReverseIndex=true cat-file --batch-check="%(objectsize:disk)" <in' ran
       77.29 ± 7.14 times faster than 'git.compile -c pack.readReverseIndex=false cat-file --batch-check="%(objectsize:disk)" <in'

, but when instead trying to compute the on-disk object size for all
objects in the repository, using the ".rev" file is a disadvantage over
creating the reverse index from scratch:

    $ hyperfine -L v false,true 'git.compile -c pack.readReverseIndex={v} cat-file --batch-check="%(objectsize:disk)" --batch-all-objects'
    Benchmark 1: git.compile -c pack.readReverseIndex=false cat-file --batch-check="%(objectsize:disk)" --batch-all-objects
      Time (mean ± σ):      8.258 s ±  0.035 s    [User: 7.949 s, System: 0.308 s]
      Range (min … max):    8.199 s …  8.293 s    10 runs

    Benchmark 2: git.compile -c pack.readReverseIndex=true cat-file --batch-check="%(objectsize:disk)" --batch-all-objects
      Time (mean ± σ):     16.976 s ±  0.107 s    [User: 16.706 s, System: 0.268 s]
      Range (min … max):   16.839 s … 17.105 s    10 runs

    Summary
      'git.compile -c pack.readReverseIndex=false cat-file --batch-check="%(objectsize:disk)" --batch-all-objects' ran
	2.06 ± 0.02 times faster than 'git.compile -c pack.readReverseIndex=true cat-file --batch-check="%(objectsize:disk)" --batch-all-objects'

Luckily, the results when running `git cat-file` with `--unordered` are
closer together:

    $ hyperfine -L v false,true 'git.compile -c pack.readReverseIndex={v} cat-file --unordered --batch-check="%(objectsize:disk)" --batch-all-objects'
    Benchmark 1: git.compile -c pack.readReverseIndex=false cat-file --unordered --batch-check="%(objectsize:disk)" --batch-all-objects
      Time (mean ± σ):      5.066 s ±  0.105 s    [User: 4.792 s, System: 0.274 s]
      Range (min … max):    4.943 s …  5.220 s    10 runs

    Benchmark 2: git.compile -c pack.readReverseIndex=true cat-file --unordered --batch-check="%(objectsize:disk)" --batch-all-objects
      Time (mean ± σ):      6.193 s ±  0.069 s    [User: 5.937 s, System: 0.255 s]
      Range (min … max):    6.145 s …  6.356 s    10 runs

    Summary
      'git.compile -c pack.readReverseIndex=false cat-file --unordered --batch-check="%(objectsize:disk)" --batch-all-objects' ran
        1.22 ± 0.03 times faster than 'git.compile -c pack.readReverseIndex=true cat-file --unordered --batch-check="%(objectsize:disk)" --batch-all-objects'

Because the equilibrium point between these two is highly machine- and
repository-dependent, allow users to configure whether or not they will
read any ".rev" file(s) with this configuration knob.

[^1]: Generating a reverse index in memory takes O(N) time (where N is
  the number of objects in the repository), since we use a radix sort.
  Reading an entry from an on-disk ".rev" file is slower since each
  operation is bound by disk I/O instead of memory I/O.

  In order to compute the on-disk size of a packed object, we need to
  find the offset of our object, and the adjacent object (the on-disk
  size difference of these two). Finding the first offset requires a
  binary search. Finding the latter involves a single .rev lookup.

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