Git development
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Sahitya Chandra <sahityajb@gmail.com>
Cc: git@vger.kernel.org, gitster@pobox.com, avarab@gmail.com,
	stolee@gmail.com, ps@pks.im
Subject: Re: [PATCH v2] wt-status: avoid repeated insertion for untracked paths
Date: Sat, 18 Jul 2026 03:31:35 -0400	[thread overview]
Message-ID: <20260718073135.GA22588@coredump.intra.peff.net> (raw)
In-Reply-To: <20260717144620.259031-1-sahityajb@gmail.com>

On Fri, Jul 17, 2026 at 08:16:20PM +0530, Sahitya Chandra wrote:

> wt_status_collect_untracked() copies entries from dir.entries and
> dir.ignored into string_lists using string_list_insert(). That keeps the
> destination lists sorted and deduplicated, but makes the code harder to
> reason about because it rebuilds sorted lists through repeated sorted
> insertion.
> 
> Collect the entries with string_list_append() instead, then sort and
> deduplicate each list once with string_list_sort_u(). This preserves the
> sorted, duplicate-free result while making the collection strategy explicit.

The patch looks good, and I think this explanation is OK-ish. But IMHO
it is still worth talking about the quadratic issue, because that's
really the motivation here (and what the "harder to reason about" is
getting at).

So maybe something like:

  wt_status_collect_untracked() copies entries from dir.entries and
  dir.ignored into string_lists using string_list_insert(). At first
  glance this seems to be quadratic, because we may shift the backing
  array, incurring O(n) work for each insert.

  In practice, though, the entries in the dir struct are already sorted,
  so each we never have to shift the array (and only pay the log-n
  lookup cost for each insertion). But this is subtle and depends on the
  behavior of fill_directory().

  Collect the entries[...etc...]

?

-Peff

  reply	other threads:[~2026-07-18  7:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-16 18:50 [PATCH] wt-status: avoid quadratic insertion for untracked paths Sahitya Chandra
2026-07-17  6:27 ` Patrick Steinhardt
2026-07-17  7:54   ` Jeff King
2026-07-17 14:40     ` Sahitya Chandra
2026-07-17 14:37   ` Sahitya Chandra
2026-07-17 14:46 ` [PATCH v2] wt-status: avoid repeated " Sahitya Chandra
2026-07-18  7:31   ` Jeff King [this message]
2026-07-18  8:05     ` Sahitya Chandra
2026-07-18  8:14   ` [PATCH v3] " Sahitya Chandra
2026-07-18  8:38     ` 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

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

  git send-email \
    --in-reply-to=20260718073135.GA22588@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=ps@pks.im \
    --cc=sahityajb@gmail.com \
    --cc=stolee@gmail.com \
    /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