From patchwork Thu Feb 1 10:25:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13540891 Received: from wfhigh4-smtp.messagingengine.com (wfhigh4-smtp.messagingengine.com [64.147.123.155]) (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 2F89F15B119 for ; Thu, 1 Feb 2024 10:25:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706783123; cv=none; b=AXBxRj0rjXD9u386m9mqJbB15C4wNY+Xge1V9tbXZ3DDB1E1EUYhypAGUXWEKujDha4cIiotMLtQ5YUBS0ty9gbBmNHJLSfCOQs470q81m/RUzktxFU2KgRRKbiae/KsZDCNPiNlJEalb/uJ3GRJc3eGSQtAMgOBMSgxUxfUoE4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706783123; c=relaxed/simple; bh=1CoiM0BAo4Y14MB2O4BLRomN+MVAgQbWGoI0OhPSRXE=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=gY8EFUejliuDQNWEiZE1pIxbKCIVZYNSkG2SDFrA756hUsnL3KEvvslODP1WSugHYlvR8EPc2XqiTM94Wr/kmOKOAakipIeIj+hJDugmukUMMfzN49YX49h1vCgQyKtL/cWMtm7uNhNeL+V+ryX+nDFVAg02gbsfi4GGzp0YZtU= 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=eMwvvJpk; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=c4RPy9Dr; arc=none smtp.client-ip=64.147.123.155 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="eMwvvJpk"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="c4RPy9Dr" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.west.internal (Postfix) with ESMTP id 45717180007A for ; Thu, 1 Feb 2024 05:25:21 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Thu, 01 Feb 2024 05:25:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=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=fm3; t=1706783120; x=1706869520; bh=rLG/PQ52GT PDY3nbMdNRAcnoU6z9+a2r/rMNHTfxskM=; b=eMwvvJpkvr437wAlPsx/IIOyRW ZekYcH9btI+tM0M4G2c6F4oiaKA/LaYsFFXTw8ux5rw5J2xEGZOxmtc7n2yNwmWv A51Pqmnx+bwBNHP96S8yWz7cTx14WuLzKp9ScFp7xzPJ4omgzla48RT1VDTA0kFN AtqDTmQlZTE2t4FpeZYTs/kWRombCwQzjCxUCwgta5war4gJY6dvBxEfOB6rGffK KV9PY24T0XdJUKHWTki8q18jIEiDfQvfZFnQ410FlyX2GRqGbVFa17VghFafvF52 gRWY5gavpZ+90EF2TVt0tDGrHHkNdrr2ZUbpZtnELKUmG9KfZCUNRtjtQV2Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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= fm3; t=1706783120; x=1706869520; bh=rLG/PQ52GTPDY3nbMdNRAcnoU6z9 +a2r/rMNHTfxskM=; b=c4RPy9DrfYHk/iwM0A+1WBZhPy5fEFFfx3ztWZ3EjXJb 8EyPhvuzxg5iI8eC02F0Yi4+Y2SedRF78zESaAZQqe4rNoJE3c9WdYC3dcma484s Vof7KlGE6RLrITtyLWE6MrJJ0Fy9aH4gCrm5DsBD8pCQwY9/U1xE2PgzXakOsSqZ Q78vDA4TYZw3k3QOhvOTO878CcNvM0Prf3NUwDuEy+ssoKn0z5PeJcEerkDgZR0m A+B1SNYr/D/eqTG2MdpW7VW7+/JE4UYbTaX7QA6UOsxJxU9oASr3XphMZPLiowRf draaGfIeZylfY6+Y8duKdWjoflLsAS1PHzcuoNTk1Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrfeduuddgudegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtjeenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhephefgjeeuveejteduhefgffefffdvjeefje eivdekfffgkeeugfehveetueefleeknecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 1 Feb 2024 05:25:20 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id a4752ee0 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Thu, 1 Feb 2024 10:21:57 +0000 (UTC) Date: Thu, 1 Feb 2024 11:25:18 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 6/7] reftable/record: don't try to reallocate ref record name Message-ID: <41dff8731c308c6d72ebd0066be8963bda725ea2.1706782841.git.ps@pks.im> 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: When decoding reftable ref records we first release the pointer to the record passed to us and then use realloc(3P) to allocate the refname array. This is a bit misleading though as we know at that point that the refname will always be `NULL`, so we would always end up allocating a new char array anyway. Refactor the code to use `REFTABLE_ALLOC_ARRAY()` instead. As the following benchmark demonstrates this is a tiny bit more efficient. But the bigger selling point really is the gained clarity. Benchmark 1: show-ref: single matching ref (revision = HEAD~) Time (mean ± σ): 150.1 ms ± 4.1 ms [User: 146.6 ms, System: 3.3 ms] Range (min … max): 144.5 ms … 180.5 ms 1000 runs Benchmark 2: show-ref: single matching ref (revision = HEAD) Time (mean ± σ): 148.9 ms ± 4.5 ms [User: 145.2 ms, System: 3.4 ms] Range (min … max): 143.0 ms … 185.4 ms 1000 runs Summary show-ref: single matching ref (revision = HEAD) ran 1.01 ± 0.04 times faster than show-ref: single matching ref (revision = HEAD~) Ideally, we should try and reuse the memory of the old record instead of first freeing and then immediately reallocating it. This requires some more surgery though and is thus left for a future iteration. Signed-off-by: Patrick Steinhardt --- reftable/record.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/reftable/record.c b/reftable/record.c index f1b6a5eac9..6465a7b8f4 100644 --- a/reftable/record.c +++ b/reftable/record.c @@ -377,10 +377,11 @@ static int reftable_ref_record_decode(void *rec, struct strbuf key, assert(hash_size > 0); - r->refname = reftable_realloc(r->refname, key.len + 1); + r->refname = reftable_malloc(key.len + 1); memcpy(r->refname, key.buf, key.len); - r->update_index = update_index; r->refname[key.len] = 0; + + r->update_index = update_index; r->value_type = val_type; switch (val_type) { case REFTABLE_REF_VAL1: