From: Jeff King <peff@peff.net>
To: "René Scharfe" <l.s.r@web.de>
Cc: Git List <git@vger.kernel.org>, Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH v2 2/2] oidset: use khash
Date: Thu, 4 Oct 2018 02:48:34 -0400 [thread overview]
Message-ID: <20181004064833.GA9051@sigill.intra.peff.net> (raw)
In-Reply-To: <d17f104e-7cc2-5e73-78c9-6c268f9ec5b2@web.de>
On Thu, Oct 04, 2018 at 07:56:44AM +0200, René Scharfe wrote:
> > As the comment above notes, I think we're really looking at the case
> > where this gets populated on the first call, but not subsequent ones. It
> > might be less hacky to use a "static int initialized" here. Or if we
> > want to avoid hidden globals, put the logic into filter_refs() to decide
> > when to populate.
>
> Right. I'd prefer the latter, but was unable to find a nice way that
> still populates the oidset lazily. It's certainly worth another look,
> and a separate series.
It's a little awkward because the lazy load happens in a conditional.
You can fully encapsulate it like the patch below, but I actually don't
think it's really helping readability.
> >> +KHASH_INIT(oid, struct object_id, int, 0, oid_hash, oid_equal)
> >
> > This will declare these "static inline". Our other major "macros become
> > inline functions" code is commit-slab.h, and there we found it necessary
> > to add MAYBE_UNUSED. I wonder if we ought to be doing the same here (I
> > don't get any warnings, but I suspect sparse might complain).
>
> I doubt it (but didn't check) because khash.h defines kh_clear_##name(),
> which we don't use it anywhere and there have been no complaints so far.
> And if we wanted to add MAYBE_UNUSED then the right place for that would
> be in KHASH_INIT, no?
Right, that would be the correct spot. I'm OK to leave it until somebody
complains. Looking at commit-slab again, its functions are straight
statics, not static inline. That's probably the important difference.
> > It might be nice if these functions could hide inside oidset.c (and just
> > declare the struct here). It looks like we might be able to do that with
> > __KHASH_TYPE(), but the double-underscore implies that we're not
> > supposed to. ;)
> >
> > I guess we also use a few of them in our inlines here. I'm not 100% sure
> > that oidset_* needs to be inlined either, but this is at least a pretty
> > faithful conversion of the original.
>
> We could inline all of the oidset functions, following the spirit of
> klib/khash.h.
>
> Or we could uninline all of them and then may be able to clean up
> oidset.h by using KHASH_DECLARE. Perhaps we'd need to guard with an
> "#ifndef THIS_IS_OIDSET_C" or similar to avoid a clash with KHASH_INIT.
>
> Not sure if any of that would be a worthwhile improvement..
Unless we know something is a performance win to inline, I'd generally
prefer not to.
For a case like this with auto-generated functions, I'm mostly worried
about bloating the compiled code. Either with a bunch of inlined
non-trivial functions, or cases where the compiler says "this is too big
to inline" and generates an anonymous file-scope function, but we end up
with a bunch of duplicates, because we're generating the same functions
in a bunch of C files.
I may be worried about nothing, though. I don't know how clever the
compiler and linker can be there.
-Peff
next prev parent reply other threads:[~2018-10-04 6:48 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-03 13:11 [PATCH v2 0/2] oidset: use khash René Scharfe
2018-10-03 13:12 ` [PATCH v2 1/2] khash: factor out kh_release_* René Scharfe
2018-10-03 13:16 ` [PATCH v2 2/2] oidset: use khash René Scharfe
2018-10-03 19:40 ` Jeff King
2018-10-04 5:56 ` René Scharfe
2018-10-04 6:48 ` Jeff King [this message]
2018-10-04 6:50 ` Jeff King
2018-10-04 15:05 ` René Scharfe
2018-10-04 15:05 ` [PATCH v3 0/5] " René Scharfe
2018-10-04 15:09 ` [PATCH v3 1/5] fetch-pack: factor out is_unmatched_ref() René Scharfe
2018-10-04 15:09 ` [PATCH v3 2/5] fetch-pack: load tip_oids eagerly iff needed René Scharfe
2018-10-04 21:38 ` Jonathan Tan
2018-10-04 22:11 ` René Scharfe
2018-10-05 20:13 ` René Scharfe
2018-10-04 22:14 ` Jeff King
2018-10-04 22:52 ` Jonathan Tan
2018-10-04 23:18 ` Jeff King
2018-10-04 22:07 ` Jeff King
2018-10-05 20:13 ` René Scharfe
2018-10-05 20:27 ` Jeff King
2018-10-05 21:22 ` René Scharfe
2018-10-05 21:47 ` Jeff King
2018-10-04 15:10 ` [PATCH v3 3/5] khash: factor out kh_release_* René Scharfe
2018-10-04 15:13 ` [PATCH v3 4/5] oidset: use khash René Scharfe
2018-10-04 15:14 ` [PATCH 5/5] oidset: uninline oidset_init() René Scharfe
2018-10-04 22:15 ` [PATCH v3 0/5] oidset: use khash Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181004064833.GA9051@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=l.s.r@web.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).