public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Tian Yuchen <cat@malon.dev>
Cc: git@vger.kernel.org, Kevin Willford <Kevin.Willford@microsoft.com>
Subject: Re: [PATCH v2] patch-ids: document intentional const-casting in patch_id_neq()
Date: Sun, 08 Mar 2026 17:26:30 -0700	[thread overview]
Message-ID: <xmqqh5qp97bd.fsf@gitster.g> (raw)
In-Reply-To: <20260308150203.86299-1-cat@malon.dev> (Tian Yuchen's message of "Sun, 8 Mar 2026 23:02:03 +0800")

Tian Yuchen <cat@malon.dev> writes:

> +	/*
> +	 * We drop the 'const' modifier here intentionally.
> +	 *
> +	 * The hashmap API requires us to treat the entries as const.
> +	 * However, to avoid performance regression, we lazily compute
> +	 * the patch IDs inside this comparison function. This fundamentally
> +	 * requires us to mutate the 'struct patch_id'. Therefore, we use
> +	 * container_of() to cast away the constness from the hashmap_entry.
> +	 */

Is that a "performance regression", I have to wonder?  We would
regress relative to what by doing what?

Is the lazy evaluation avoiding unnecessary work?

If we are going to pass _all_ the objects in the hashmap to this
comparator function eventually _anyway_, then the total cost of
computing patch IDs to all of them in the hashmap would not change
with or without lazy computation, but if we are currently getting
away without having to compute for all, but only computing for the
ones we pass to this function, then lazy evaluation is clearly a
win.  I do not offhand know which of the above two is the case, but
we need to know that before we can touch the NEEDSWORK comment, I
think.

The lazy computation comes from b3dfeebb (rebase: avoid computing
unnecessary patch IDs, 2016-07-29), even though the "const
correctness?" comment is a bit newer than that.

So it seems that we indeed are avoiding unnecessary work without
this patch.  We'd encounter "performance regression" only if we stop
avoiding unnecessary work, so I am afraid that the phrasing used in
the patch is somewhat confusing.

    Even though eptr and entry_or_key are const, we want to lazily
    compute their .patch_id members; see b3dfeebb (rebase: avoid
    computing unnecessary patch IDs, 2016-07-29), so cast the
    constness away with container_of().

or something, perhaps?

>  	struct diff_options *opt = (void *)cmpfn_data;
>  	struct patch_id *a, *b;

  reply	other threads:[~2026-03-09  0:26 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-08  4:31 [PATCH] patch-ids: achieve const correctness in patch_id_neq() Tian Yuchen
2026-03-08  6:26 ` Junio C Hamano
2026-03-08 14:42   ` Tian Yuchen
2026-03-08 15:02 ` [PATCH v2] patch-ids: document intentional const-casting " Tian Yuchen
2026-03-09  0:26   ` Junio C Hamano [this message]
2026-03-09  6:39     ` cat
2026-03-09  6:51   ` [PATCH v3] " Tian Yuchen

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqh5qp97bd.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=Kevin.Willford@microsoft.com \
    --cc=cat@malon.dev \
    --cc=git@vger.kernel.org \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox