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

Re: [PATCH 8/8] cache-tree: avoid path comparison loop when silent

From
Elijah Newren <newren@gmail.com>
Date
Dec 30, 2020, 20:14 UTC
Message-ID
<CABPp-BFp5=C+6B1WUarXzabo0fU4xotP5UG91-hYahCHDA6Cng@mail.gmail.com>
In-Reply-To
<20ea7050324cdd78b0966f54366b26224dfc7814.1609356414.git.gitgitgadget@gmail.com>

On Wed, Dec 30, 2020 at 11:27 AM Derrick Stolee via GitGitGadget <gitgitgadget@gmail.com> wrote:

Show 17 quoted lines
>
> From: Derrick Stolee <dstolee@microsoft.com>
>
> The verify_cache() method is used both for debugging issues with the
> cached tree extension but also to avoid using the extension when there
> are unmerged entries. It also checks for cache entries out of order with
> respect to file-versus-directory sorting.
>
> In 996277c (Refactor cache_tree_update idiom from commit, 2011-12-06),
> the silent option was added to remove the progress indicators from the
> initial loop looking for unmerged entries. This was changed to be a flag
> in e859c69 (cache-tree: update API to take abitrary flags, 2012-01-16).
>
> In both cases, the silent option is ignored for the second loop that
> checks for file-versus-directory sorting. It must be that this loop is
> intended only for debugging purposes and is not actually helpful in
> practice.

Looking through that code, I come to the same conclusion, though it might be nice to have Junio confirm (and to explain the "if (10 < ++funny)" section; did that help debugging too?). The second part of the loop was part of his initial commit adding the cache-tree extension in commit 749864627c ("Add cache-tree.", 2006-04-23)

Show 9 quoted lines
> Since verify_cache() is called in cache_tree_update(), which is run
> during 'git commit', we could speed up 'git commit' operations by not
> iterating through this loop another time. Of course, noticing this loop
> requires an incredibly large index.
>
> To get a measurable difference, I needed to run this test on the
> Microsoft Office monorepo, which has over three million entries in its
> index. I used 'git commit --amend --no-edit' as my command and saw the
> performance go from 752ms to 739ms with this change.

Nice catch; I always appreciate when we can speed up a section of code by just not running it. :-)

Show 30 quoted lines
>
> Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
> ---
>  cache-tree.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/cache-tree.c b/cache-tree.c
> index f135bb77af5..c6c084463bd 100644
> --- a/cache-tree.c
> +++ b/cache-tree.c
> @@ -175,10 +175,15 @@ static int verify_cache(struct cache_entry **cache,
>         if (funny)
>                 return -1;
>
> -       /* Also verify that the cache does not have path and path/file
> +       /*
> +        * Also verify that the cache does not have path and path/file
>          * at the same time.  At this point we know the cache has only
> -        * stage 0 entries.
> +        * stage 0 entries. In silent mode, we do not want these messages,
> +        * and they should not exist unless a bug was introduced along
> +        * the way.
>          */
> +       if (silent)
> +               return 0;
>         funny = 0;
>         for (i = 0; i < entries - 1; i++) {
>                 /* path/file always comes after path because of the way
> --
> gitgitgadget

Change seems simple enough. Thanks for adding the comment explaining the early return.

Previous: Derrick Stolee via GitGitGadgetNext: Junio C Hamano
Message 12 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.