git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 07/10] index-format: update preamble to cache tree extension

From
Derrick Stolee via GitGitGadget <gitgitgadget@gmail.com>
Date
Jan 7, 2021, 16:32 UTC
Message-ID
<c5cffb5956ee2f8e55210b64b6686c4cd1c839b6.1610037132.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.829.v3.git.1610037131.gitgitgadget@gmail.com>
From: Derrick Stolee <dstolee@microsoft.com>

I had difficulty in my efforts to learn about the cache tree extension based on the documentation and code because I had an incorrect assumption about how it behaved. This might be due to some ambiguity in the documentation, so this change modifies the beginning of the cached tree format by expanding the description of the feature.

My hope is that this documentation clarifies a few things:
1. There is an in-memory recursive tree structure that is constructed
   from the extension data. This structure has a few differences, such
   as where the name is stored.
2. What does it mean for an entry to be invalid?
3. When exactly are "new" trees created?
Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
---
 Documentation/technical/index-format.txt | 33 +++++++++++++++++++-----
 1 file changed, 27 insertions(+), 6 deletions(-)
diff --git a/Documentation/technical/index-format.txt b/Documentation/technical/index-format.txt
index c71314731ec..65dcfa570df 100644
--- a/Documentation/technical/index-format.txt
+++ b/Documentation/technical/index-format.txt
@@ -138,12 +138,33 @@ Git index format
 
 === Cache tree
 
-  Cache tree extension contains pre-computed hashes for trees that can
-  be derived from the index. It helps speed up tree object generation
-  from index for a new commit.
-
-  When a path is updated in index, the path must be invalidated and
-  removed from tree cache.
+  Since the index does not record entries for directories, the cache
+  entries cannot describe tree objects that already exist in the object
+  database for regions of the index that are unchanged from an existing
+  commit. The cache tree extension stores a recursive tree structure that
+  describes the trees that already exist and completely match sections of
+  the cache entries. This speeds up tree object generation from the index
+  for a new commit by only computing the trees that are "new" to that
+  commit. It also assists when comparing the index to another tree, such
+  as `HEAD^{tree}`, since sections of the index can be skipped when a tree
+  comparison demonstrates equality.
+
+  The recursive tree structure uses nodes that store a number of cache
+  entries, a list of subnodes, and an object ID (OID). The OID references
+  the existing tree for that node, if it is known to exist. The subnodes
+  correspond to subdirectories that themselves have cache tree nodes. The
+  number of cache entries corresponds to the number of cache entries in
+  the index that describe paths within that tree's directory.
+
+  The extension tracks the full directory structure in the cache tree
+  extension, but this is generally smaller than the full cache entry list.
+
+  When a path is updated in index, Git invalidates all nodes of the
+  recursive cache tree corresponding to the parent directories of that
+  path. We store these tree nodes as being "invalid" by using "-1" as the
+  number of cache entries. Invalid nodes still store a span of index
+  entries, allowing Git to focus its efforts when reconstructing a full
+  cache tree.
 
   The signature for this extension is { 'T', 'R', 'E', 'E' }.
 
-- 
gitgitgadget
Previous: Derrick Stolee via GitGitGadgetNext: Junio C Hamano
Message 52 of 53 in “Cleanups around index operations”
  1. 0/8 Cleanups around index operationsDerrick Stolee via GitGitGadget, Dec 30, 2020
  2. 1/8 tree-walk: report recursion countsDerrick Stolee via GitGitGadget, Dec 30, 2020
  3. Elijah NewrenDec 30, 2020
  4. Derrick StoleeDec 30, 2020
  5. 3/8 cache-tree: use trace2 in cache_tree_update()Derrick Stolee via GitGitGadget, Dec 30, 2020
  6. 2/8 unpack-trees: add trace2 regionsDerrick Stolee via GitGitGadget, Dec 30, 2020
  7. Elijah NewrenDec 30, 2020
  8. 4/8 cache-tree: trace regions for I/ODerrick Stolee via GitGitGadget, Dec 30, 2020
  9. 6/8 index-format: update preamble to cached tree extensionDerrick Stolee via GitGitGadget, Dec 30, 2020
  10. Elijah NewrenDec 30, 2020
  11. 8/8 cache-tree: avoid path comparison loop when silentDerrick Stolee via GitGitGadget, Dec 30, 2020
  12. Elijah NewrenDec 30, 2020
  13. Junio C HamanoJan 6, 2021
  14. Derrick StoleeJan 6, 2021
  15. René ScharfeDec 31, 2020
  16. Derrick StoleeDec 31, 2020
  17. René ScharfeJan 1, 2021
  18. cache-tree: use ce_namelen() instead of strlen()René Scharfe, Jan 2, 2021
  19. Derrick StoleeJan 4, 2021
  20. Junio C HamanoJan 5, 2021
  21. René ScharfeJan 2, 2021
  22. 5/8 cache-tree: trace regions for prime_cache_treeDerrick Stolee via GitGitGadget, Dec 30, 2020
  23. Elijah NewrenDec 30, 2020
  24. Derrick StoleeDec 30, 2020
  25. 7/8 index-format: discuss recursion of cached-tree betterDerrick Stolee via GitGitGadget, Dec 30, 2020
  26. Elijah NewrenDec 30, 2020
  27. Derrick StoleeDec 30, 2020
  28. 0/9 Cleanups around index operationsDerrick Stolee via GitGitGadget, Jan 4, 2021
  29. 2/9 unpack-trees: add trace2 regionsDerrick Stolee via GitGitGadget, Jan 4, 2021
  30. 4/9 cache-tree: trace regions for I/ODerrick Stolee via GitGitGadget, Jan 4, 2021
  31. 1/9 tree-walk: report recursion countsDerrick Stolee via GitGitGadget, Jan 4, 2021
  32. 3/9 cache-tree: use trace2 in cache_tree_update()Derrick Stolee via GitGitGadget, Jan 4, 2021
  33. 5/9 cache-tree: trace regions for prime_cache_treeDerrick Stolee via GitGitGadget, Jan 4, 2021
  34. 6/9 index-format: update preamble to cached tree extensionDerrick Stolee via GitGitGadget, Jan 4, 2021
  35. Junio C HamanoJan 7, 2021
  36. Derrick StoleeJan 7, 2021
  37. Junio C HamanoJan 7, 2021
  38. Junio C HamanoJan 7, 2021
  39. 7/9 index-format: discuss recursion of cached-tree betterDerrick Stolee via GitGitGadget, Jan 4, 2021
  40. 9/9 cache-tree: speed up consecutive path comparisonsDerrick Stolee via GitGitGadget, Jan 4, 2021
  41. 8/9 cache-tree: use ce_namelen() instead of strlen()René Scharfe via GitGitGadget, Jan 4, 2021
  42. 00/10 Cleanups around index operationsDerrick Stolee via GitGitGadget, Jan 7, 2021
  43. 01/10 tree-walk: report recursion countsDerrick Stolee via GitGitGadget, Jan 7, 2021
  44. 02/10 unpack-trees: add trace2 regionsDerrick Stolee via GitGitGadget, Jan 7, 2021
  45. 03/10 cache-tree: use trace2 in cache_tree_update()Derrick Stolee via GitGitGadget, Jan 7, 2021
  46. 04/10 cache-tree: trace regions for I/ODerrick Stolee via GitGitGadget, Jan 7, 2021
  47. 06/10 index-format: use 'cache tree' over 'cached tree'Derrick Stolee via GitGitGadget, Jan 7, 2021
  48. 08/10 index-format: discuss recursion of cached-tree betterDerrick Stolee via GitGitGadget, Jan 7, 2021
  49. 09/10 cache-tree: use ce_namelen() instead of strlen()René Scharfe via GitGitGadget, Jan 7, 2021
  50. 10/10 cache-tree: speed up consecutive path comparisonsDerrick Stolee via GitGitGadget, Jan 7, 2021
  51. 05/10 cache-tree: trace regions for prime_cache_treeDerrick Stolee via GitGitGadget, Jan 7, 2021
  52. 07/10 index-format: update preamble to cache tree extensionDerrick Stolee via GitGitGadget, Jan 7, 2021
  53. Junio C HamanoJan 16, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.