git-commit-vandalism/Documentation
Taylor Blau 2f4ba2a867 packfile: prepare for the existence of '*.rev' files
Specify the format of the on-disk reverse index 'pack-*.rev' file, as
well as prepare the code for the existence of such files.

The reverse index maps from pack relative positions (i.e., an index into
the array of object which is sorted by their offsets within the
packfile) to their position within the 'pack-*.idx' file. Today, this is
done by building up a list of (off_t, uint32_t) tuples for each object
(the off_t corresponding to that object's offset, and the uint32_t
corresponding to its position in the index). To convert between pack and
index position quickly, this array of tuples is radix sorted based on
its offset.

This has two major drawbacks:

First, the in-memory cost scales linearly with the number of objects in
a pack.  Each 'struct revindex_entry' is sizeof(off_t) +
sizeof(uint32_t) + padding bytes for a total of 16.

To observe this, force Git to load the reverse index by, for e.g.,
running 'git cat-file --batch-check="%(objectsize:disk)"'. When asking
for a single object in a fresh clone of the kernel, Git needs to
allocate 120+ MB of memory in order to hold the reverse index in memory.

Second, the cost to sort also scales with the size of the pack.
Luckily, this is a linear function since 'load_pack_revindex()' uses a
radix sort, but this cost still must be paid once per pack per process.

As an example, it takes ~60x longer to print the _size_ of an object as
it does to print that entire object's _contents_:

  Benchmark #1: git.compile cat-file --batch <obj
    Time (mean ± σ):       3.4 ms ±   0.1 ms    [User: 3.3 ms, System: 2.1 ms]
    Range (min … max):     3.2 ms …   3.7 ms    726 runs

  Benchmark #2: git.compile cat-file --batch-check="%(objectsize:disk)" <obj
    Time (mean ± σ):     210.3 ms ±   8.9 ms    [User: 188.2 ms, System: 23.2 ms]
    Range (min … max):   193.7 ms … 224.4 ms    13 runs

Instead, avoid computing and sorting the revindex once per process by
writing it to a file when the pack itself is generated.

The format is relatively straightforward. It contains an array of
uint32_t's, the length of which is equal to the number of objects in the
pack.  The ith entry in this table contains the index position of the
ith object in the pack, where "ith object in the pack" is determined by
pack offset.

One thing that the on-disk format does _not_ contain is the full (up to)
eight-byte offset corresponding to each object. This is something that
the in-memory revindex contains (it stores an off_t in 'struct
revindex_entry' along with the same uint32_t that the on-disk format
has). Omit it in the on-disk format, since knowing the index position
for some object is sufficient to get a constant-time lookup in the
pack-*.idx file to ask for an object's offset within the pack.

This trades off between the on-disk size of the 'pack-*.rev' file for
runtime to chase down the offset for some object. Even though the lookup
is constant time, the constant is heavier, since it can potentially
involve two pointer walks in v2 indexes (one to access the 4-byte offset
table, and potentially a second to access the double wide offset table).

Consider trying to map an object's pack offset to a relative position
within that pack. In a cold-cache scenario, more page faults occur while
switching between binary searching through the reverse index and
searching through the *.idx file for an object's offset. Sure enough,
with a cold cache (writing '3' into '/proc/sys/vm/drop_caches' after
'sync'ing), printing out the entire object's contents is still
marginally faster than printing its size:

  Benchmark #1: git.compile cat-file --batch-check="%(objectsize:disk)" <obj >/dev/null
    Time (mean ± σ):      22.6 ms ±   0.5 ms    [User: 2.4 ms, System: 7.9 ms]
    Range (min … max):    21.4 ms …  23.5 ms    41 runs

  Benchmark #2: git.compile cat-file --batch <obj >/dev/null
    Time (mean ± σ):      17.2 ms ±   0.7 ms    [User: 2.8 ms, System: 5.5 ms]
    Range (min … max):    15.6 ms …  18.2 ms    45 runs

(Numbers taken in the kernel after cheating and using the next patch to
generate a reverse index). There are a couple of approaches to improve
cold cache performance not pursued here:

  - We could include the object offsets in the reverse index format.
    Predictably, this does result in fewer page faults, but it triples
    the size of the file, while simultaneously duplicating a ton of data
    already available in the .idx file. (This was the original way I
    implemented the format, and it did show
    `--batch-check='%(objectsize:disk)'` winning out against `--batch`.)

    On the other hand, this increase in size also results in a large
    block-cache footprint, which could potentially hurt other workloads.

  - We could store the mapping from pack to index position in more
    cache-friendly way, like constructing a binary search tree from the
    table and writing the values in breadth-first order. This would
    result in much better locality, but the price you pay is trading
    O(1) lookup in 'pack_pos_to_index()' for an O(log n) one (since you
    can no longer directly index the table).

So, neither of these approaches are taken here. (Thankfully, the format
is versioned, so we are free to pursue these in the future.) But, cold
cache performance likely isn't interesting outside of one-off cases like
asking for the size of an object directly. In real-world usage, Git is
often performing many operations in the revindex (i.e., asking about
many objects rather than a single one).

The trade-off is worth it, since we will avoid the vast majority of the
cost of generating the revindex that the extra pointer chase will look
like noise in the following patch's benchmarks.

This patch describes the format and prepares callers (like in
pack-revindex.c) to be able to read *.rev files once they exist. An
implementation of the writer will appear in the next patch, and callers
will gradually begin to start using the writer in the patches that
follow after that.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-01-25 18:32:43 -08:00
..
config Merge branch 'sj/untracked-files-in-submodule-directory-is-not-dirty' 2021-01-25 14:19:18 -08:00
howto Merge branch 'js/pu-to-seen' 2020-07-06 22:09:16 -07:00
RelNotes The fourth batch 2021-01-25 14:19:20 -08:00
technical packfile: prepare for the existence of '*.rev' files 2021-01-25 18:32:43 -08:00
.gitattributes
.gitignore
asciidoc.conf Doc: drop support for docbook-xsl before 1.72.0 2020-03-29 09:25:38 -07:00
asciidoctor-extensions.rb Merge branch 'ma/user-manual-markup-update' 2019-10-06 12:25:16 +09:00
blame-options.txt blame-options.txt: also mention 'funcname' in '-L' description 2020-11-01 15:54:14 -08:00
build-docdep.perl Documentation/build-docdep.perl: Fix dependencies for included asciidoc files 2007-03-01 13:24:54 -08:00
cat-texi.perl
cmd-list.perl git.txt: add list of guides 2020-08-04 18:34:02 -07:00
CodingGuidelines Merge branch 'dl/python-2.7-is-the-floor-version' 2020-06-17 21:54:05 -07:00
config.txt Merge branch 'sn/config-doc-typofix' 2020-12-08 15:11:22 -08:00
date-formats.txt date-formats.txt: fix list continuation 2020-05-18 13:18:56 -07:00
diff-format.txt doc: indent multi-line items in list 2019-12-13 12:18:07 -08:00
diff-generate-patch.txt git.txt: correct stale 'GIT_EXTERNAL_DIFF' description 2020-09-01 12:17:05 -07:00
diff-options.txt Merge branch 'pb/blame-funcname-range-userdiff' 2020-11-18 13:32:53 -08:00
doc-diff doc-diff: use single-colon rule in rendering Makefile 2020-02-18 13:53:30 -08:00
docbook-xsl.css
docbook.xsl
everyday.txto Documentation: fix linkgit references 2016-05-09 15:44:14 -07:00
fetch-options.txt fetch: implement support for atomic reference updates 2021-01-12 12:06:15 -08:00
fix-texi.perl
git-add.txt add: support the --pathspec-from-file option 2019-12-04 10:10:37 -08:00
git-am.txt Documentation: stylistically normalize references to Signed-off-by: 2020-10-20 11:57:40 -07:00
git-annotate.txt
git-apply.txt git-apply.txt: update descriptions of --cached, --index 2020-08-20 16:34:37 -07:00
git-archimport.txt
git-archive.txt archive: add --add-file 2020-09-19 15:56:06 -07:00
git-bisect-lk2009.txt git-bisect-lk2009: make continuation of list indented 2020-10-08 14:01:15 -07:00
git-bisect.txt bisect: swap command-line options in documentation 2020-08-28 14:06:06 -07:00
git-blame.txt mailmap doc: create a new "gitmailmap(5)" man page 2021-01-12 14:04:39 -08:00
git-branch.txt doc: clarify that --abbrev=<n> is about the minimum length 2020-11-04 14:04:44 -08:00
git-bugreport.txt Merge branch 'es/bugreport-shell' 2020-06-08 18:06:28 -07:00
git-bundle.txt bundle: add new version for use with SHA-256 2020-07-30 09:16:48 -07:00
git-cat-file.txt cat-file: add missing [=<format>] to usage/synopsis 2020-07-01 15:54:05 -07:00
git-check-attr.txt Documentation: fix a bunch of typos, both old and new 2019-11-07 13:42:00 +09:00
git-check-ignore.txt Merge branch 'en/check-ignore' into maint 2020-03-17 15:02:23 -07:00
git-check-mailmap.txt check-mailmap doc: note config options 2021-01-12 14:04:40 -08:00
git-check-ref-format.txt
git-checkout-index.txt
git-checkout.txt Merge branch 'dl/checkout-guess' 2020-10-27 15:09:51 -07:00
git-cherry-pick.txt Documentation: stylistically normalize references to Signed-off-by: 2020-10-20 11:57:40 -07:00
git-cherry.txt
git-citool.txt
git-clean.txt Merge branch 'en/clean-nested-with-ignored' 2019-10-11 14:24:46 +09:00
git-clone.txt Documentation/git-clone.txt: document race with --local 2021-01-11 22:03:08 -08:00
git-column.txt
git-commit-graph.txt Merge branch 'ds/commit-graph-merging-fix' 2020-11-02 13:17:39 -08:00
git-commit-tree.txt Documentation: merge commit-tree --[no-]gpg-sign 2020-04-03 11:37:22 -07:00
git-commit.txt doc: preparatory clean-up of description on the sign-off option 2020-10-20 11:57:35 -07:00
git-config.txt Merge branch 'ps/config-env-pairs' 2021-01-25 14:19:19 -08:00
git-count-objects.txt
git-credential-cache--daemon.txt
git-credential-cache.txt
git-credential-store.txt Merge branch 'cb/credential-store-ignore-bogus-lines' 2020-05-08 14:25:01 -07:00
git-credential.txt git-credential.txt: use list continuation 2020-05-18 13:19:33 -07:00
git-cvsexportcommit.txt
git-cvsimport.txt
git-cvsserver.txt Documentation: fix a bunch of typos, both old and new 2019-11-07 13:42:00 +09:00
git-daemon.txt
git-describe.txt
git-diff-files.txt
git-diff-index.txt builtin/diff-index: learn --merge-base 2020-09-20 21:30:26 -07:00
git-diff-tree.txt builtin/diff-tree: learn --merge-base 2020-09-21 13:37:03 -07:00
git-diff.txt builtin/diff-tree: learn --merge-base 2020-09-21 13:37:03 -07:00
git-difftool.txt
git-fast-export.txt fast-export: allow seeding the anonymized mapping 2020-06-25 14:19:23 -07:00
git-fast-import.txt fast-import: fix typo in documentation 2020-10-04 12:56:29 -07:00
git-fetch-pack.txt Documentation: fix several one-character-off spelling errors 2018-04-09 14:15:02 +09:00
git-fetch.txt fetch: allow refspecs specified through stdin 2020-08-18 13:25:05 -07:00
git-filter-branch.txt filter-branch doc: fix filter-repo typo 2020-10-20 12:22:25 -07:00
git-fmt-merge-msg.txt
git-for-each-ref.txt Doc: prefer more specific file name 2020-09-18 15:41:56 -07:00
git-for-each-repo.txt for-each-repo: run subcommands on configured repos 2020-09-25 10:59:44 -07:00
git-format-patch.txt Merge branch 'jc/format-patch-name-max' 2020-11-21 15:14:38 -08:00
git-fsck-objects.txt
git-fsck.txt Documentation/git-fsck.txt: include fsck.* config variables 2019-07-29 10:41:18 -07:00
git-gc.txt Recommend git-filter-repo instead of git-filter-branch 2019-09-05 13:01:48 -07:00
git-get-tar-commit-id.txt
git-grep.txt doc: add more pointers to gitattributes(5) for userdiff 2020-11-01 15:54:14 -08:00
git-gui.txt Documentation: update the location of the git-gui repo 2019-10-06 09:45:02 +09:00
git-hash-object.txt
git-help.txt help: drop usage of 'common' and 'useful' for guides 2020-08-04 18:34:01 -07:00
git-http-backend.txt
git-http-fetch.txt http-fetch: support fetching packfiles by URL 2020-06-10 18:06:34 -07:00
git-http-push.txt
git-imap-send.txt git-imap-send.txt: add note about localized Gmail folders 2020-08-31 11:44:33 -07:00
git-index-pack.txt Documentation: mark --object-format=sha256 as experimental 2020-08-17 10:50:14 -07:00
git-init-db.txt
git-init.txt init: document init.defaultBranch better 2020-12-13 15:53:50 -08:00
git-instaweb.txt
git-interpret-trailers.txt
git-log.txt doc: log, gitk: move '-L' description to 'line-range-options.txt' 2020-11-01 15:54:14 -08:00
git-ls-files.txt doc: remove "directory cache" from man pages 2021-01-09 22:57:24 -08:00
git-ls-remote.txt docs: adjust for the recent rename of pu to seen 2020-06-25 09:18:53 -07:00
git-ls-tree.txt doc: clarify that --abbrev=<n> is about the minimum length 2020-11-04 14:04:44 -08:00
git-mailinfo.txt Doc: show example scissors line 2020-09-28 16:09:04 -07:00
git-mailsplit.txt
git-maintenance.txt Merge branch 'ds/maintenance-part-4' 2021-01-15 21:48:45 -08:00
git-merge-base.txt git-merge-base.txt: render indentations correctly under Asciidoctor 2019-09-09 11:05:51 -07:00
git-merge-file.txt
git-merge-index.txt git-merge-index.txt: wrap shell listing in "----" 2019-09-09 11:05:52 -07:00
git-merge-one-file.txt
git-merge-tree.txt
git-merge.txt Doc: reference the "stash list" in autostash docs 2020-05-05 16:07:30 -07:00
git-mergetool--lib.txt
git-mergetool.txt
git-mktag.txt mktag: add a --[no-]strict option 2021-01-06 14:22:24 -08:00
git-mktree.txt
git-multi-pack-index.txt multi-pack-index: repack batches below --batch-size 2020-08-11 14:05:26 -07:00
git-mv.txt
git-name-rev.txt
git-notes.txt docs: improve the example that illustrates git-notes path names 2020-08-03 12:40:09 -07:00
git-p4.txt doc: fix some typos 2021-01-04 11:27:48 -08:00
git-pack-objects.txt pack-objects: no fetch when allow-{any,promisor} 2020-08-06 13:01:03 -07:00
git-pack-redundant.txt
git-pack-refs.txt
git-patch-id.txt
git-prune-packed.txt
git-prune.txt
git-pull.txt Merge branch 'dl/merge-autostash' 2020-04-29 16:15:27 -07:00
git-push.txt t, doc: update tests, reference for "--force-if-includes" 2020-10-03 09:59:19 -07:00
git-quiltimport.txt
git-range-diff.txt Merge branch 'dl/range-diff-with-notes' 2019-12-05 12:52:44 -08:00
git-read-tree.txt doc: --recurse-submodules mostly applies to active submodules 2020-04-06 13:42:43 -07:00
git-rebase.txt Documentation: stylistically normalize references to Signed-off-by: 2020-10-20 11:57:40 -07:00
git-receive-pack.txt git-receive-pack.txt: wrap shell [script] listing in "----" 2019-09-09 11:05:52 -07:00
git-reflog.txt
git-remote-ext.txt
git-remote-fd.txt
git-remote-helpers.txto
git-remote.txt remote: add meaningful exit code on missing/existing 2020-10-27 11:40:33 -07:00
git-repack.txt doc: fix repeated words 2019-08-11 17:40:07 -07:00
git-replace.txt Recommend git-filter-repo instead of git-filter-branch 2019-09-05 13:01:48 -07:00
git-request-pull.txt doc: keep first level section header in upper case 2018-05-02 17:03:33 +09:00
git-rerere.txt Merge branch 'nd/switch-and-restore' 2019-07-09 15:25:44 -07:00
git-reset.txt doc: document --recurse-submodules for reset and restore 2020-04-06 13:42:43 -07:00
git-restore.txt Doc: document "A...B" form for <tree-ish> in checkout and switch 2020-10-07 09:49:05 -07:00
git-rev-list.txt git-log.txt: include rev-list-description.txt 2020-07-08 22:08:54 -07:00
git-rev-parse.txt rev-parse: add option for absolute or relative path formatting 2020-12-12 23:35:51 -08:00
git-revert.txt Documentation: stylistically normalize references to Signed-off-by: 2020-10-20 11:57:40 -07:00
git-rm.txt rm: support the --pathspec-from-file option 2020-02-19 10:56:49 -08:00
git-send-email.txt Merge branch 'vv/send-email-with-less-secure-apps-access' 2021-01-15 21:48:46 -08:00
git-send-pack.txt
git-sh-i18n--envsubst.txt
git-sh-i18n.txt
git-sh-setup.txt
git-shell.txt
git-shortlog.txt mailmap doc: create a new "gitmailmap(5)" man page 2021-01-12 14:04:39 -08:00
git-show-branch.txt
git-show-index.txt Documentation: mark --object-format=sha256 as experimental 2020-08-17 10:50:14 -07:00
git-show-ref.txt
git-show.txt
git-sparse-checkout.txt Merge branch 'en/sparse-with-submodule-doc' 2020-06-22 15:55:03 -07:00
git-stage.txt
git-stash.txt stash push: support the --pathspec-from-file option 2020-02-19 10:56:49 -08:00
git-status.txt docs: rephrase and clarify the git status --short format 2021-01-11 12:14:07 -08:00
git-stripspace.txt
git-submodule.txt submodule: fall back to remote's HEAD for missing remote.<name>.branch 2020-06-24 09:14:21 -07:00
git-svn.txt Documentation: stylistically normalize references to Signed-off-by: 2020-10-20 11:57:40 -07:00
git-switch.txt checkout: learn to respect checkout.guess 2020-10-08 09:25:29 -07:00
git-symbolic-ref.txt
git-tag.txt Doc: prefer more specific file name 2020-09-18 15:41:56 -07:00
git-tools.txt
git-unpack-file.txt
git-unpack-objects.txt
git-update-index.txt doc: remove "directory cache" from man pages 2021-01-09 22:57:24 -08:00
git-update-ref.txt update-ref: allow creation of multiple transactions 2020-11-16 13:44:01 -08:00
git-update-server-info.txt
git-upload-archive.txt
git-upload-pack.txt
git-var.txt
git-verify-commit.txt
git-verify-pack.txt
git-verify-tag.txt
git-web--browse.txt
git-whatchanged.txt
git-worktree.txt worktree: teach repair to fix multi-directional breakage 2020-12-21 13:44:28 -08:00
git-write-tree.txt
git.txt Merge branch 'ps/config-env-pairs' 2021-01-25 14:19:19 -08:00
gitattributes.txt userdiff: support Bash 2020-10-22 10:29:30 -07:00
gitcli.txt Merge branch 'jc/doc-single-h-is-for-help' into maint 2020-03-17 15:02:24 -07:00
gitcore-tutorial.txt doc/gitcore-tutorial: fix prose to match example command 2020-01-08 08:56:40 -08:00
gitcredentials.txt command-list.txt: add missing 'gitcredentials' and 'gitremote-helpers' 2020-08-04 18:34:01 -07:00
gitcvs-migration.txt
gitdiffcore.txt
giteveryday.txt docs: adjust for the recent rename of pu to seen 2020-06-25 09:18:53 -07:00
gitfaq.txt docs: explain how to deal with files that are always modified 2020-09-20 21:29:02 -07:00
gitglossary.txt
githooks.txt doc: fix some typos 2021-01-04 11:27:48 -08:00
gitignore.txt Merge branch 'an/ignore-doc-update' into maint 2019-07-25 14:27:13 -07:00
gitk.txt doc: log, gitk: move '-L' description to 'line-range-options.txt' 2020-11-01 15:54:14 -08:00
gitmailmap.txt mailmap doc: use correct environment variable 'GIT_WORK_TREE' 2021-01-14 21:54:06 -08:00
gitmodules.txt gitmodules.txt: fix 'GIT_WORK_TREE' variable name 2021-01-04 11:29:36 -08:00
gitnamespaces.txt
gitremote-helpers.txt Merge branch 'bc/sha-256-part-2' 2020-07-06 22:09:13 -07:00
gitrepository-layout.txt Merge branch 'sg/dir-trie-fixes' 2019-11-10 18:02:14 +09:00
gitrevisions.txt
gitsubmodules.txt gitsubmodules doc: invoke 'ls-files' with '--recurse-submodules' 2020-10-04 12:54:07 -07:00
gittutorial-2.txt
gittutorial.txt
gitweb.conf.txt gitweb.conf.txt: switch pluses to backticks to help Asciidoctor 2019-09-09 11:05:52 -07:00
gitweb.txt doc: don't use git.kernel.org as example gitweb URL 2019-06-24 12:37:21 -07:00
gitworkflows.txt gitworkflows.txt: fix broken subsection underline 2020-07-18 13:43:34 -07:00
glossary-content.txt glossary: improve "branch" definition 2020-12-02 14:53:42 -08:00
howto-index.sh
i18n.txt
install-doc-quick.sh
install-webdoc.sh
line-range-format.txt doc: add more pointers to gitattributes(5) for userdiff 2020-11-01 15:54:14 -08:00
line-range-options.txt blame-options.txt: also mention 'funcname' in '-L' description 2020-11-01 15:54:14 -08:00
lint-gitlink.perl
Makefile mailmap doc: create a new "gitmailmap(5)" man page 2021-01-12 14:04:39 -08:00
manpage-base-url.xsl.in
manpage-bold-literal.xsl manpage-bold-literal.xsl: stop using git.docbook.backslash 2020-03-29 09:25:38 -07:00
manpage-normal.xsl manpage-normal.xsl: fold in manpage-base.xsl 2020-03-29 09:25:38 -07:00
manpage-quote-apos.xsl
manpage.xsl Documentation: fix build with Asciidoctor 2 2019-09-16 12:20:39 -07:00
merge-options.txt doc: preparatory clean-up of description on the sign-off option 2020-10-20 11:57:35 -07:00
merge-strategies.txt merge-strategies: fix typo "reflected to" to "reflected in" 2019-11-11 11:04:46 +09:00
MyFirstContribution.txt Merge branch 'jc/do-not-just-explain-but-update-your-patch' 2020-11-30 14:49:43 -08:00
MyFirstObjectWalk.txt MyFirstObjectWalk: drop init_walken_defaults() 2020-11-30 13:55:54 -08:00
object-format-disclaimer.txt Documentation: mark --object-format=sha256 as experimental 2020-08-17 10:50:14 -07:00
pretty-formats.txt pretty format %(trailers): add a "key_value_separator" 2020-12-09 14:16:42 -08:00
pretty-options.txt doc: clarify that --abbrev=<n> is about the minimum length 2020-11-04 14:04:44 -08:00
pull-fetch-param.txt refspec: add support for negative refspecs 2020-09-30 14:52:00 -07:00
ref-reachability-filters.txt Doc: prefer more specific file name 2020-09-18 15:41:56 -07:00
rev-list-description.txt git-log.txt: include rev-list-description.txt 2020-07-08 22:08:54 -07:00
rev-list-options.txt Merge branch 'jk/log-fp-implies-m' 2020-08-17 17:02:49 -07:00
revisions.txt revisions.txt: describe 'rev1 rev2 ...' meaning for ranges 2020-07-08 22:08:53 -07:00
sequencer.txt cherry-pick/revert: add --skip option 2019-07-02 12:08:08 -07:00
signoff-option.txt Documentation: stylistically normalize references to Signed-off-by: 2020-10-20 11:57:40 -07:00
SubmittingPatches SubmittingPatches: tighten wording on "sign-off" procedure 2021-01-07 15:41:36 -08:00
texi.xsl
trace2-target-values.txt docs: mention trace2 target-dir mode in git-config 2019-10-04 09:26:42 +09:00
transfer-data-leaks.txt
urls-remotes.txt
urls.txt Doc: Bundle file usage 2019-10-21 12:02:39 +09:00
user-manual.conf user-manual.conf: don't specify [listingblock] 2020-03-31 16:08:02 -07:00
user-manual.txt docs: adjust for the recent rename of pu to seen 2020-06-25 09:18:53 -07:00