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

Re: [PATCH] ref-filter: sort numerically when ":size" is used

From
Jeff King <peff@peff.net>
Date
Sep 1, 2023, 20:51 UTC
Message-ID
<20230901205145.GB1960498@coredump.intra.peff.net>
In-Reply-To
<xmqq7cp9prux.fsf@gitster.g>
On Fri, Sep 01, 2023 at 01:21:10PM -0700, Junio C Hamano wrote:
Show 15 quoted lines
> Jeff King <peff@peff.net> writes:
> 
> > But I think that is the wrong way to optimize it. We shouldn't be
> > storing any strings per-atom, but rather walking the parse tree to
> > produce a single output buffer. And the values should be cheap to fill
> > in, because we should parse the object as necessary up front. This is
> > more or less the way the pretty.c parser does it.
> 
> I thought "as necessary" may be a bit tricky as populate_value()
> were taught to omit doing the whole get_object() thing when the
> values for used_atom[] are all computable without parsing the object
> at all, but it seems that over time the populate_value() callchain
> has degraded sufficiently to unconditionally call get_object() these
> days, so I agree that the arrangement does not have much optimization
> value, at least in the current code.

No, I think we still do that optimization. When parsing the format string, the parser function for each atom sets fields in an object_info struct to indicate what we're interested in. Then for each ref, we call populate_value(). If that object_info doesn't need anything (we byte-wise compare it to an empty dummy struct), then we return early, before calling get_object().

And that optimization is very important to retain; it makes a format like %(refname) an order of magnitude faster.

The optimization I was referring to is that if you have a format like:
  %(contents:body) %(contents:body)

then we'll de-duplicate that to a single used_atom struct, and they'll share the same v->s result string. That's much harder to do if you parse into an abstract syntax tree, since the two occupy different parts of the tree. But my contention is that it does not matter if you stop allocating v->s in the first place, and just walk the tree to directly output the result (either to a strbuf or directly to stdout).

-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 9 of 14 in “ref-filter: sort numerically when ":size" is used”
  1. ref-filter: sort numerically when ":size" is usedKousik Sanagavarapu, Sep 1, 2023
  2. Junio C HamanoSep 1, 2023
  3. Jeff KingSep 1, 2023
  4. Junio C HamanoSep 1, 2023
  5. Jeff KingSep 1, 2023
  6. Kousik SanagavarapuSep 1, 2023
  7. Jeff KingSep 1, 2023
  8. Junio C HamanoSep 1, 2023
  9. Jeff KingSep 1, 2023
  10. Junio C HamanoSep 1, 2023
  11. Jeff KingSep 1, 2023
  12. ref-filter: sort numerically when ":size" is usedKousik Sanagavarapu, Sep 2, 2023
  13. Kousik SanagavarapuSep 2, 2023
  14. Junio C HamanoSep 2, 2023

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.