From patchwork Tue Feb 27 15:06:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13573996 Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) (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 BD02B1487D5 for ; Tue, 27 Feb 2024 15:06:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.25 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709046420; cv=none; b=mVqd8KsHr/3371QwMZr+LugXjyVhfoT1ZbzS+XdamiyvksPaK2M8JvelDwzFkW2alKK+51QY3qozWoew0Nz1dhetX865IukqdA6sxKqlZoVEaejyyCbzOpd/skMhb5nyU9Vj+vM94JqZRdeqcCvj44M8dLgt//Cbi/6S3oyFAq0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709046420; c=relaxed/simple; bh=1fNfgntGirVyJUjKcEVOw/Yoyf7ld8XeUgPTYFbGbHg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=eafGmwIfU6fHjVYzawZlRytco1PMuXLlDIozflIuUEErizto20O0ZHFR83qc8jymbHaW5RH2Y+Yrw3biMHm0Ywlwu3Fg13xMzSzR6G7VZpYlWCVwo9a5mllATuWRtevapy6kSNkcZzP65JPbyfH+mUyLE16wUeqTHykNUitUDs4= 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=LzJv6UJL; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=rxrmXYAf; arc=none smtp.client-ip=64.147.123.25 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="LzJv6UJL"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="rxrmXYAf" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id D7C143200922; Tue, 27 Feb 2024 10:06:57 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Tue, 27 Feb 2024 10:06:58 -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=1709046417; x=1709132817; bh=Ji/jbGu0ZO qX54dJV1fXdrNeYX6FgHCVECLnqzJKhjs=; b=LzJv6UJLCjQfL1EIEuvvYnpmEj k2QtfO0QOucgwSvH3VgkhI6wf+LhhrC9idJ52Vk54M6AxasLw5GTqnpyGXfQTACK CpBtEY7T5pZO68KPbnRUeeWFnFoiQgfcbjNZiRkmM0xiOHmT1S/1/pAlkK3kZvdy SYkZrXRuWxyj/Jv98FUCHUuHukC/Z31NeoLzIZZj/ZhwzGW+Mc9FtAQUqL9lCFNW mOjSWTfEfi7tG0GrIw307gbVBlFO/6gTmF8qB+tszIebCnrMPmWhrN9PBGtEMhhi 0czFUfXKTvH8jAIImSnXJXBwgiMYavyqFn0rsQQJu8yJRDsTfeylt3i9fKfw== 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=1709046417; x=1709132817; bh=Ji/jbGu0ZOqX54dJV1fXdrNeYX6F gHCVECLnqzJKhjs=; b=rxrmXYAfrqkyRowL3qmjCFpVzKBmOc8A32FHZ0kvhMZ2 S9pq+8zjI3GSoyDZzvC5rkTCylWia0NNNOCh9BSpP3iSzaaWHGU667hrq04PqDJ3 K9Js+2Zq2V3V3UIMMe3mhdEWhHFXQIk8q47yfxCAf9exueISRWZv4D/gzJAatWbt RL7OjkIVwvX5pXbFnKi19LbUyAXIZ2UFgo2zghAgQgrHJOEgIkM8MdquFaDzXm7S d9qY6jOQ+1O9x4lc9D6rd0yIiKXNLCclxtBk1EP1J8kQPK/c68ft49EOIAN0gVOO quknFsHfHajOQItXtQQlvSSunDkAzTlBQy0Y2j6pgg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrgeehgdegkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtuggjsehgtderredttdejnecuhfhrohhmpefrrghtrhhi tghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrh hnpeetueevhffhudefvdegieeuieelgedthfegfedtueevjeejtdfgjeehudejuedtuden ucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesph hkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 27 Feb 2024 10:06:56 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 9c37f06f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 27 Feb 2024 15:02:39 +0000 (UTC) Date: Tue, 27 Feb 2024 16:06:55 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler Subject: [PATCH v2 10/13] reftable/record: reuse refname when copying Message-ID: <35b1af2f0612e51bc0cf87afe9c44197b2b8ccaf.1709045927.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: Do the same optimization as in the preceding commit, but this time for `reftable_record_copy()`. While not as noticeable, it still results in a small speedup when iterating over 1 million refs: Benchmark 1: show-ref: single matching ref (revision = HEAD~) Time (mean ± σ): 114.0 ms ± 3.8 ms [User: 111.1 ms, System: 2.7 ms] Range (min … max): 110.9 ms … 144.3 ms 1000 runs Benchmark 2: show-ref: single matching ref (revision = HEAD) Time (mean ± σ): 112.5 ms ± 3.7 ms [User: 109.5 ms, System: 2.8 ms] Range (min … max): 109.2 ms … 140.7 ms 1000 runs Summary show-ref: single matching ref (revision = HEAD) ran 1.01 ± 0.05 times faster than show-ref: single matching ref (revision = HEAD~) Signed-off-by: Patrick Steinhardt --- reftable/record.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/reftable/record.c b/reftable/record.c index e800cfef00..3f2a639036 100644 --- a/reftable/record.c +++ b/reftable/record.c @@ -205,14 +205,26 @@ static void reftable_ref_record_copy_from(void *rec, const void *src_rec, { struct reftable_ref_record *ref = rec; const struct reftable_ref_record *src = src_rec; + char *refname = NULL; + size_t refname_cap = 0; + assert(hash_size > 0); - /* This is simple and correct, but we could probably reuse the hash - * fields. */ + SWAP(refname, ref->refname); + SWAP(refname_cap, ref->refname_cap); reftable_ref_record_release(ref); + SWAP(refname, ref->refname); + SWAP(refname_cap, ref->refname_cap); + if (src->refname) { - ref->refname = xstrdup(src->refname); + size_t refname_len = strlen(src->refname); + + REFTABLE_ALLOC_GROW(ref->refname, refname_len + 1, + ref->refname_cap); + memcpy(ref->refname, src->refname, refname_len); + ref->refname[refname_len] = 0; } + ref->update_index = src->update_index; ref->value_type = src->value_type; switch (src->value_type) {