From patchwork Mon Mar 4 10:49:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13580398 Received: from wfhigh1-smtp.messagingengine.com (wfhigh1-smtp.messagingengine.com [64.147.123.152]) (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 BF87537168 for ; Mon, 4 Mar 2024 10:49:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709549349; cv=none; b=T5Z762YpUnYVEJOHYZQA134LgTuTZUr5AdXhv7ek2SLcgwoPE5o3it8teYKigKrJe6oqtD9pjtpCl41izTvrXwzj8Xx3tCnG5cMBkCq5BoWQufcLhMdgxSWDBM3BtKK6nmS97Us8JW9t38IvzMvPhJ0cJKqZUOnW7sJ+89hIops= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709549349; c=relaxed/simple; bh=w2DTV972ahOSJpinc5cfiFuyXQD22YGlKTjoOSE0yko=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=l6tW6XrdrEXL9bV1yZvJirGXrQU68bXXC4ssXlpKaWd51Pa4kpyB7iVtULFwP6WK6/81+hDURt9l3eYm9g/rUxQAT8Mx3nmWB5WKSSQJYxrbGGQgoTDC84TMhXG0VSP6X9GqXqLHY1adDU7SE+Qn339UsmHIgmD6hH7gI7VHvCU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=OEbfF549; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=TLm9Myde; arc=none smtp.client-ip=64.147.123.152 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="OEbfF549"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="TLm9Myde" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfhigh.west.internal (Postfix) with ESMTP id 9C8FC18000A9; Mon, 4 Mar 2024 05:49:06 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Mon, 04 Mar 2024 05:49:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; 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=1709549346; x=1709635746; bh=XliPYTK0RB f8NUWc6N7GoRYBP1y0xRXLd0RGjrIYWro=; b=OEbfF549TnTZd2UzSyiBztSt9R stPpFPUvh10a+O+ftODhoBWv7ZGENWeNQIMO1h1r5iSLgO52QvTBTdO3ZMHHz1AE +3Tx1lsnXE7dI0bYCQHC5sVeHvBuvlFR/4vygAeu31E3bPYPpLHxF4Jv9kHENiTO Jl/WJOSvqf0/0aiCBfa1KpXZTnxqRti+knq75RhWd/HjGbYRS2fcA2PxbYg5wUwZ 2KkTPkGtUIjYXauodGPASKT6PCvJuE1XZ3m/IEV6Zq+YDVq1ppa9IeTyhEy8BoMz 4lb+Jn34c/5u0kBA6agou46geSAbIEPg2gXHMA1tW1cBWA2LciuaOiTBVpaQ== 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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1709549346; x=1709635746; bh=XliPYTK0RBf8NUWc6N7GoRYBP1y0 xRXLd0RGjrIYWro=; b=TLm9MydedhS7QRH4mFX8OF6C9ooMtgsyv+Hol2wStoPI F6Sy6DMOFAYPtC566g2+PYwQVXE57spvn0iReQC4Og33H/FBEZbXNINzBU19T4J5 F4tVYhD5nQ5Lo5HLqM8VHHTAbKDbnAHZuklpPQOARTtbgCG2MarUx7O4Y6nmxoKd /begxIKJmYvzejcJoH4eL/pK1rk6yJFhdqaFYvpIjcdPNlmM73S9rv8bPrGJVydh EMVJwZNvAeEt110vsj/k5jkAf3fHcqO9sP+FeW3g5Ui0uh3ccUweXtxcLaCMkFZY V7lDV1Wt3VSqj4L+JZzsDoPyd3CCGPDqJyv3+qprlw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrheejgddulecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtuggjsehgtderredttdejnecuhfhrohhmpefrrghtrhhi tghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrh hnpeetueevhffhudefvdegieeuieelgedthfegfedtueevjeejtdfgjeehudejuedtuden ucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesph hkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 4 Mar 2024 05:49:05 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id af12d105 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 4 Mar 2024 10:44:40 +0000 (UTC) Date: Mon, 4 Mar 2024 11:49:03 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , James Liu Subject: [PATCH v3 05/13] reftable/merged: remove unnecessary null check for subiters Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Whenever we advance a subiter we first call `iterator_is_null()`. This is not needed though because we only ever advance subiters which have entries in the priority queue, and we do not end entries to the priority queue when the subiter has been exhausted. Drop the check as well as the now-unused function. This results in a surprisingly big speedup: Benchmark 1: show-ref: single matching ref (revision = HEAD~) Time (mean ± σ): 138.1 ms ± 4.4 ms [User: 135.1 ms, System: 2.8 ms] Range (min … max): 133.4 ms … 167.3 ms 1000 runs Benchmark 2: show-ref: single matching ref (revision = HEAD) Time (mean ± σ): 134.4 ms ± 4.2 ms [User: 131.5 ms, System: 2.8 ms] Range (min … max): 130.0 ms … 164.0 ms 1000 runs Summary show-ref: single matching ref (revision = HEAD) ran 1.03 ± 0.05 times faster than show-ref: single matching ref (revision = HEAD~) Signed-off-by: Patrick Steinhardt --- reftable/iter.c | 5 ----- reftable/iter.h | 4 ---- reftable/merged.c | 10 +--------- 3 files changed, 1 insertion(+), 18 deletions(-) diff --git a/reftable/iter.c b/reftable/iter.c index 8b5ebf6183..7aa30c4a51 100644 --- a/reftable/iter.c +++ b/reftable/iter.c @@ -16,11 +16,6 @@ license that can be found in the LICENSE file or at #include "reader.h" #include "reftable-error.h" -int iterator_is_null(struct reftable_iterator *it) -{ - return !it->ops; -} - static void filtering_ref_iterator_close(void *iter_arg) { struct filtering_ref_iterator *fri = iter_arg; diff --git a/reftable/iter.h b/reftable/iter.h index 47d67d84df..537431baba 100644 --- a/reftable/iter.h +++ b/reftable/iter.h @@ -16,10 +16,6 @@ license that can be found in the LICENSE file or at #include "reftable-iterator.h" #include "reftable-generic.h" -/* Returns true for a zeroed out iterator, such as the one returned from - * iterator_destroy. */ -int iterator_is_null(struct reftable_iterator *it); - /* iterator that produces only ref records that point to `oid` */ struct filtering_ref_iterator { int double_check; diff --git a/reftable/merged.c b/reftable/merged.c index ae74234472..29ad09f3d8 100644 --- a/reftable/merged.c +++ b/reftable/merged.c @@ -70,8 +70,7 @@ static void merged_iter_close(void *p) reftable_free(mi->subiters); } -static int merged_iter_advance_nonnull_subiter(struct merged_iter *mi, - size_t idx) +static int merged_iter_advance_subiter(struct merged_iter *mi, size_t idx) { struct pq_entry e = { .index = idx, @@ -92,13 +91,6 @@ static int merged_iter_advance_nonnull_subiter(struct merged_iter *mi, return 0; } -static int merged_iter_advance_subiter(struct merged_iter *mi, size_t idx) -{ - if (iterator_is_null(&mi->subiters[idx].iter)) - return 0; - return merged_iter_advance_nonnull_subiter(mi, idx); -} - static int merged_iter_next_entry(struct merged_iter *mi, struct reftable_record *rec) {