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

Re: [PATCH 5/5] load_ref_decorations(): avoid parsing non-tag objects

From
Jeff King <peff@peff.net>
Date
Jun 22, 2021, 18:57 UTC
Message-ID
<YNIyn7dksqMtkuk/@coredump.intra.peff.net>
In-Reply-To
<875yy53juu.fsf@evledraar.gmail.com>
On Tue, Jun 22, 2021 at 07:06:43PM +0200, Ævar Arnfjörð Bjarmason wrote:
Show 18 quoted lines
> > @@ -155,9 +156,10 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid,
> >  		return 0;
> >  	}
> >  
> > -	obj = parse_object(the_repository, oid);
> > -	if (!obj)
> > +	objtype = oid_object_info(the_repository, oid, NULL);
> > +	if (type < 0)
> >  		return 0;
> > +	obj = lookup_object_by_type(the_repository, oid, objtype);
> 
> This series looks good. I just wonder if between this and my own
> lookup_{blob,tree,tag,commit}_type() in [1] whether exposing some
> function between what we have now in parse_object() and
> parse_object_buffer() wouldn't also do this for you.
> 
> I.e. in my patch if you pass a type into parse_object_buffer() I think
> you'll get the same behavior.

Maybe, but I'm having trouble seeing what would be a helpful abstraction. I don't think I'd want to use parse_object_buffer() here; we don't have a buffer at all (and obviously it could learn to handle NULL, but that's extra code there).

parse_object_buffer() could call this lookup_object_by_type() to get the struct, which would save it a few lines. But it still has to do the if-else chain for each type, because it does other type-specific things.

So I dunno. I would be happy if you came up with something, just because it's nice to minimize the number of places that do this if-else/switch on type. But I have a feeling it's diminishing returns in terms of complexity. If we can at least contain it all to object.c, that's something.

-Peff
Previous: Ævar Arnfjörð BjarmasonNext: Taylor Blau
Message 14 of 16 in “some "log --decorate" optimizations”
  1. 0/5 some "log --decorate" optimizationsJeff King, Jun 22, 2021
  2. 1/5 pretty.h: update and expand docstring for userformat_find_requirements()Jeff King, Jun 22, 2021
  3. 2/5 log: avoid loading decorations for userformats that don't need itJeff King, Jun 22, 2021
  4. 3/5 object.h: expand docstring for lookup_unknown_object()Jeff King, Jun 22, 2021
  5. 4/5 object.h: add lookup_object_by_type() functionJeff King, Jun 22, 2021
  6. 5/5 load_ref_decorations(): avoid parsing non-tag objectsJeff King, Jun 22, 2021
  7. Derrick StoleeJun 22, 2021
  8. Jeff KingJun 22, 2021
  9. Jeff KingJun 22, 2021
  10. Derrick StoleeJun 22, 2021
  11. Ævar Arnfjörð BjarmasonJun 22, 2021
  12. Jeff KingJun 22, 2021
  13. Ævar Arnfjörð BjarmasonJun 22, 2021
  14. Jeff KingJun 22, 2021
  15. Taylor BlauJun 23, 2021
  16. Jeff KingJun 23, 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.