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

Re: [hacky PATCH 0/2] speeding up trivial for-each-ref invocations

From
ZheNing Hu <adlternative@gmail.com>
Date
Sep 5, 2021, 08:19 UTC
Message-ID
<CAOLTT8RzHb5zWUm1psZRTP=iST-jP4DBmG2Zh1UPdo6z+QyHcg@mail.gmail.com>
In-Reply-To
<YTNpQ7Od1U/5i0R7@coredump.intra.peff.net>
Jeff King <peff@peff.net> 于2021年9月4日周六 下午8:40写道:
Show 14 quoted lines
>
> Somebody complained to me off-list recently that for-each-ref was slow
> when doing a trivial listing (like refname + objectname) of a large
> number of refs, even though you could get mostly the same output by
> just dumping the packed-refs file.
>
> So I was nerd-sniped into making this horrible series, which does speed
> up some cases. It was a combination of "how fast can we easily get it",
> plus I was curious _which_ parts of for-each-ref were actually slow.
>
> In this version there are 2 patches, tested against 'git for-each-ref
> --format="%(objectname) %(refname)"' on a fully packed repo with 500k
> refs:
>
Regarding this 500k refs, is there any way I can reproduce it?
Show 27 quoted lines
>   - directly outputting items rather than building up a ref_array yields
>     about a 1.5x speedup
>
>   - avoiding the whole atom-formatting system yields a 2.5x speedup on
>     top of that
>
> I had originally written it against a slightly older version of Git,
> before show_ref_array_item() was inlined. In that version, there was a
> middle ground where we still created a ref_array_item for each ref, and
> then fed it to the "quick" formatter (so we could see the cost of
> having to malloc/free a bunch of ref_array_item structs). The numbers
> there wre:
>
>   - streaming out items gave a 1.5x speedup
>
>   - using the "quick" formatter gave a 1.8x speedup
>
>   - avoiding the extra malloc/free for each item gave a 1.4x
>
> which makes sense; 1.8 * 1.4 is ~2.5, so it's the same speedup just
> broken down further.
>
> I'm not sure I'm really advocating that we should do something like
> this, though it is tempting because it does make some common queries
> much faster. But I wanted to share it here to give some insight on where
> the time may be going in ref-filter / for-each-ref.
>

Well, this acceleration looks gratifying. But so far I haven't seen its effect on git cat-file --batch | --batch-check.

Show 9 quoted lines
>   [1/2]: ref-filter: hacky "streaming" mode
>   [2/2]: ref-filter: implement "quick" formats
>
>  builtin/for-each-ref.c |   7 +++
>  ref-filter.c           | 113 +++++++++++++++++++++++++++++++++++++----
>  ref-filter.h           |  21 ++++++++
>  3 files changed, 132 insertions(+), 9 deletions(-)
>
> -Peff
Previous: Junio C HamanoNext: Jeff King
Message 21 of 26 in “speeding up trivial for-each-ref invocations”
  1. 0/2 speeding up trivial for-each-ref invocationsJeff King, Sep 4, 2021
  2. 1/2 ref-filter: hacky "streaming" modeJeff King, Sep 4, 2021
  3. ZheNing HuSep 5, 2021
  4. Jeff KingSep 5, 2021
  5. ZheNing HuSep 7, 2021
  6. Jeff KingSep 7, 2021
  7. ZheNing HuSep 9, 2021
  8. Jeff KingSep 10, 2021
  9. ZheNing HuSep 15, 2021
  10. ZheNing HuSep 15, 2021
  11. Jeff KingSep 16, 2021
  12. ZheNing HuSep 20, 2021
  13. Jeff KingSep 16, 2021
  14. Jeff KingSep 5, 2021
  15. ZheNing HuSep 7, 2021
  16. 2/2 ref-filter: implement "quick" formatsJeff King, Sep 4, 2021
  17. ZheNing HuSep 5, 2021
  18. Jeff KingSep 5, 2021
  19. ZheNing HuSep 6, 2021
  20. Junio C HamanoSep 7, 2021
  21. ZheNing HuSep 5, 2021
  22. Jeff KingSep 5, 2021
  23. ZheNing HuSep 6, 2021
  24. Jeff KingSep 7, 2021
  25. ZheNing HuSep 9, 2021
  26. Patrick SteinhardtSep 6, 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.