From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from fout-b6-smtp.messagingengine.com (fout-b6-smtp.messagingengine.com [202.12.124.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1C7E3368A2 for ; Fri, 24 Jul 2026 15:27:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.149 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784906831; cv=none; b=Za06ja8EYPiZGmGpL4qVd4OZZw83asnbGdJnI/wzcyGtvtkqiSeajwXwqEI84pbaPVDAHzixrTCV1v2NWF+M5PUgWsiNmEHQ4O/LX9ak/v12KKjKsMqqeyzVRLYglPyxqYYnjmP7UMCVQB8YHbBMmfI9C70RAmZNbGYaYrKe/8E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784906831; c=relaxed/simple; bh=zvjZf+cqVS6E1OLfyGbs/6ut1/Ylg9qmn6UkClieNb0=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=kFx7ccjvj2Y0R4mheQ313qIwJc+0ePO8lfXvMgbghJK1sk43cPVdTIPwA+IYG8Odj+q7qs6F5pl08fiXfF6N0xN82vwbisYy1M1lei7Dx9OrKJiOAhYWNrAuMMJvn1kMsUnL3aJMvH3B4vZ0VPjURFFSOsRxF9GB/CQfh6pRr6M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (2048-bit key) header.d=pobox.com header.i=@pobox.com header.b=QlUs8Y4f; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=BjXznuMe; arc=none smtp.client-ip=202.12.124.149 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pobox.com header.i=@pobox.com header.b="QlUs8Y4f"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="BjXznuMe" Received: from phl-compute-02.internal (phl-compute-02.internal [10.202.2.42]) by mailfout.stl.internal (Postfix) with ESMTP id E6C711D0007D; Fri, 24 Jul 2026 11:27:08 -0400 (EDT) Received: from phl-frontend-01 ([10.202.2.160]) by phl-compute-02.internal (MEProxy); Fri, 24 Jul 2026 11:27:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pobox.com; h=cc :cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1784906828; x=1784993228; bh=Ct5/shxcDs HOvOy4nYKFT1drG/eMJjvNCWMkOZ/5TTA=; b=QlUs8Y4fAT/iDclbCfivLHBaW5 TMZZqTO6o79YW/6T5++f8DGTbrcwEmw1gohABV9tKan2q196yX269fiDc8pD/gPx MhPZIEqfCYAsVe4PSpUuvcjf8BLMWG1wASu94GE1fmO5RR9xiUc0v/ZxlYdtME2G wE1fDD48lZx3qyghEhu4vtWBCYcGWTEg4kjnHPL51gWa61mFf/ZgArlIFc4B2p+z qf9UhzzEJ+BOth01DXTR7uzBKkxiCOL+C4QrMYKK19kIkVIFhlQ5Hb/9umGc1d4r DmJ/hwYliOw4DRiHWkXjEtgcQy0z3jqX1SDTPamLutri2bbnrJ0KhwaiH0Dg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1784906828; x=1784993228; bh=Ct5/shxcDsHOvOy4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cnH4sQ5bK4LIAXtRL+xQRThWvWKPTS9r373kXA78g4w X-ME-Proxy: Feedback-ID: if26b431b:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 24 Jul 2026 11:27:08 -0400 (EDT) From: Junio C Hamano To: tnyman@openai.com Cc: git@vger.kernel.org, haraldnordgren@gmail.com Subject: Re: [PATCH] branch: avoid slow strvec Coccinelle matching In-Reply-To: <20260724091152.27794-2-tnyman@openai.com> (tnyman@openai.com's message of "Fri, 24 Jul 2026 02:11:53 -0700") References: <20260724091152.27794-2-tnyman@openai.com> Date: Fri, 24 Jul 2026 08:27:06 -0700 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain tnyman@openai.com writes: > From: Ted Nyman > > The --delete-merged implementation declares a loop index at function > scope and reuses it to walk its strvec of upstreams and its list of > candidate branches. Coccinelle 1.1.1 spends hours matching this against > the separate_loop_index rule in tools/coccinelle/strvec.cocci, causing > the static-analysis job on 'seen' to reach its six-hour timeout. > ... > The CI failure reproduces locally with Coccinelle 1.1.1: applying > strvec.cocci to the original builtin/branch.c still times out with > "spatch --timeout 120". With this change, the same check completes in > 0.06 seconds. Impressive. Nicely analyzed. Even though this is very much like bending the code only to appease the checker, the resulting code is arguably better in this particular case, so I do not feel as bad as I have on other occasions when we had to work around deficiencies in our tools [*]. I see Harald already took this in the latest update. Thanks for working well together. [*] * Here, I do not blame Coccinelle alone. The performance bug is caused by a combination of Coccinelle and the 'strvec' check that makes it so inefficient. I wonder if there are ways to make the checks in 'strvec.cocci' more efficient? > diff --git a/builtin/branch.c b/builtin/branch.c > index 42f2221547..2415a275ea 100644 > --- a/builtin/branch.c > +++ b/builtin/branch.c > @@ -797,10 +797,9 @@ static int delete_merged_branches(const struct strvec *upstreams, > struct strbuf key = STRBUF_INIT; > struct hashmap_iter iter; > struct strmap_entry *entry; > - size_t i; > int ret = 0; > > - for (i = 0; i < upstreams->nr; i++) > + for (size_t i = 0; i < upstreams->nr; i++) > if (ref_filter_forked_add(&filter, upstreams->v[i]) < 0) > die(_("'%s' is not a valid branch or pattern"), > upstreams->v[i]); > @@ -809,7 +808,7 @@ static int delete_merged_branches(const struct strvec *upstreams, > filter.name_patterns = argv; > filter_refs(&candidates, &filter, filter.kind); > > - for (i = 0; i < (size_t)candidates.nr; i++) { > + for (size_t i = 0; i < (size_t)candidates.nr; i++) { > const char *branch_refname = candidates.items[i]->refname; > const char *branch_name; > struct branch *branch;