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

Re: [PATCH 1/8] tree-walk: report recursion counts

From
Derrick Stolee <stolee@gmail.com>
Date
Dec 30, 2020, 19:51 UTC
Message-ID
<b81e853a-64ef-dbe5-77d3-f3a2cf87c9bc@gmail.com>
In-Reply-To
<CABPp-BHQY0v2GwmV6dokkTPGuJKmFYKJ7NCe2kes0pQbZgBGQQ@mail.gmail.com>
On 12/30/2020 2:42 PM, Elijah Newren wrote:
Show 8 quoted lines
> On Wed, Dec 30, 2020 at 11:26 AM Derrick Stolee via GitGitGadget
> <gitgitgadget@gmail.com> wrote:
>>
>> From: Derrick Stolee <dstolee@microsoft.com>
>>
>> The traverse_trees() method recusively walks through trees, but also
> 
> recursively -- you're missing the second 'r'.
Thanks.
Show 6 quoted lines
>> prunes the tree-walk based on a callback. Some callers, such as
>> unpack_trees(), are quite complicated and can have wildly different
>> performance between two different commands.
> 
> Not sure it belongs in the commit message, but you do have me curious
> what you're digging in to...
I'm still testing whether my idea will work out. Hopefully soon. ;)
 
Show 14 quoted lines
>> Create constants that count these values and then report the results at
>> the end of a process. These counts are cumulative across multiple "root"
>> instances of traverse_trees(), but they provide reproducible values for
>> demonstrating improvements to the pruning algorithm when possible.
>>
>> Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
>> ---
>>  tree-walk.c    | 33 +++++++++++++++++++++++++++++++++
>>  unpack-trees.c |  1 -
>>  2 files changed, 33 insertions(+), 1 deletion(-)
> 
> From the subject, you are changing tree-walk.  unpack-trees depends on
> tree-walk, but why is something exposed to it with this kind of
> change?  Maybe I'll see when I get to it.

Oops. I originally reported the stats at the end of unpack_trees(), but it seems I didn't completely back out that change.

Show 38 quoted lines
>> diff --git a/tree-walk.c b/tree-walk.c
>> index 0160294712b..2d6226d5f18 100644
>> --- a/tree-walk.c
>> +++ b/tree-walk.c
>> @@ -4,6 +4,7 @@
>>  #include "object-store.h"
>>  #include "tree.h"
>>  #include "pathspec.h"
>> +#include "json-writer.h"
>>
>>  static const char *get_mode(const char *str, unsigned int *modep)
>>  {
>> @@ -167,6 +168,25 @@ int tree_entry_gently(struct tree_desc *desc, struct name_entry *entry)
>>         return 1;
>>  }
>>
>> +static int traverse_trees_atexit_registered;
>> +static int traverse_trees_count;
>> +static int traverse_trees_cur_depth;
>> +static int traverse_trees_max_depth;
>> +
>> +static void trace2_traverse_trees_statistics_atexit(void)
>> +{
>> +       struct json_writer jw = JSON_WRITER_INIT;
>> +
>> +       jw_object_begin(&jw, 0);
>> +       jw_object_intmax(&jw, "traverse_trees_count", traverse_trees_count);
>> +       jw_object_intmax(&jw, "traverse_trees_max_depth", traverse_trees_max_depth);
>> +       jw_end(&jw);
>> +
>> +       trace2_data_json("traverse_trees", the_repository, "statistics", &jw);
>> +
>> +       jw_release(&jw);
>> +}
> 
> Yeah, I don't know the json_writer or trace2 stuff; might be nice to
> cc Josh Steadmon or someone to review this patch.  (Or perhaps he
> already reviewed internally?)

I guess I could have pointed out that this change is modeled after a similar statistics reporting in 42e50e78 (revision.c: add trace2 stats around Bloom filter usage, 2020-04-06).

Show 54 quoted lines
>> +
>>  void setup_traverse_info(struct traverse_info *info, const char *base)
>>  {
>>         size_t pathlen = strlen(base);
>> @@ -180,6 +200,11 @@ void setup_traverse_info(struct traverse_info *info, const char *base)
>>         info->namelen = pathlen;
>>         if (pathlen)
>>                 info->prev = &dummy;
>> +
>> +       if (trace2_is_enabled() && !traverse_trees_atexit_registered) {
>> +               atexit(trace2_traverse_trees_statistics_atexit);
>> +               traverse_trees_atexit_registered = 1;
>> +       }
>>  }
>>
>>  char *make_traverse_path(char *path, size_t pathlen,
>> @@ -416,6 +441,12 @@ int traverse_trees(struct index_state *istate,
>>         int interesting = 1;
>>         char *traverse_path;
>>
>> +       traverse_trees_count++;
>> +       traverse_trees_cur_depth++;
>> +
>> +       if (traverse_trees_cur_depth > traverse_trees_max_depth)
>> +               traverse_trees_max_depth = traverse_trees_cur_depth;
>> +
>>         if (n >= ARRAY_SIZE(entry))
>>                 BUG("traverse_trees() called with too many trees (%d)", n);
>>
>> @@ -515,6 +546,8 @@ int traverse_trees(struct index_state *istate,
>>         free(traverse_path);
>>         info->traverse_path = NULL;
>>         strbuf_release(&base);
>> +
>> +       traverse_trees_cur_depth--;
> 
> I double-checked to see if there were any other return sites in this
> function.  There aren't, which is nice and keeps this clean.
> 
>>         return error;
>>  }
>>
>> diff --git a/unpack-trees.c b/unpack-trees.c
>> index 323280dd48b..02f484604ac 100644
>> --- a/unpack-trees.c
>> +++ b/unpack-trees.c
>> @@ -1559,7 +1559,6 @@ static void populate_from_existing_patterns(struct unpack_trees_options *o,
>>         free(sparse);
>>  }
>>
>> -
> 
> Did you mean to combine this cleanup with some other patch?  If not,
> could it be put into its own patch?
It should be dropped! Thanks.
Show 9 quoted lines
>>  static int verify_absent(const struct cache_entry *,
>>                          enum unpack_trees_error_types,
>>                          struct unpack_trees_options *);
>> --
>> gitgitgadget
> 
> Seems like a good change other than a few small nits.  I don't know
> the json_writer/trace2 stuff, so you might want another reviewer, but
> it's only a few lines and seems relatively straightforward.

I should point out that an easy way to test this locally is to run

  GIT_TRACE2_PERF=1 git read-tree -mu HEAD

to trigger a full recursive walk. The output JSON payload looks like this:

  statistics:{"traverse_trees_count":203,"traverse_trees_max_depth":7}

Thanks, -Stolee

Previous: Elijah NewrenNext: Derrick Stolee via GitGitGadget
Message 4 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.