git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Cc: Eric Sunshine <sunshine@sunshineco.com>, John Cai <johncai86@gmail.com>
Subject: [PATCH v2 6/7] reftable/record: don't try to reallocate ref record name
Date: Mon, 12 Feb 2024 09:32:53 +0100	[thread overview]
Message-ID: <8c674915044c47c46c8e4efcb4d914fdd26e5c55.1707726654.git.ps@pks.im> (raw)
In-Reply-To: <cover.1707726654.git.ps@pks.im>

[-- Attachment #1: Type: text/plain, Size: 2046 bytes --]

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 <ps@pks.im>
---
 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:
-- 
2.43.GIT


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2024-02-12  8:32 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-01 10:24 [PATCH 0/7] reftable: improve ref iteration performance Patrick Steinhardt
2024-02-01 10:24 ` [PATCH 1/7] reftable/record: introduce function to compare records by key Patrick Steinhardt
2024-02-01 15:00   ` Eric Sunshine
2024-02-01 10:25 ` [PATCH 2/7] reftable/merged: allocation-less dropping of shadowed records Patrick Steinhardt
2024-02-01 10:25 ` [PATCH 3/7] reftable/merged: skip comparison for records of the same subiter Patrick Steinhardt
2024-02-01 17:29   ` Eric Sunshine
2024-02-02  5:15     ` Patrick Steinhardt
2024-02-01 10:25 ` [PATCH 4/7] reftable/pq: allocation-less comparison of entry keys Patrick Steinhardt
2024-02-01 10:25 ` [PATCH 5/7] reftable/block: swap buffers instead of copying Patrick Steinhardt
2024-02-01 10:25 ` [PATCH 6/7] reftable/record: don't try to reallocate ref record name Patrick Steinhardt
2024-02-01 10:25 ` [PATCH 7/7] reftable/reader: add comments to `table_iter_next()` Patrick Steinhardt
2024-02-09 16:01   ` John Cai
2024-02-12  8:24     ` Patrick Steinhardt
2024-02-12  8:32 ` [PATCH v2 0/7] reftable: improve ref iteration performance Patrick Steinhardt
2024-02-12  8:32   ` [PATCH v2 1/7] reftable/record: introduce function to compare records by key Patrick Steinhardt
2024-02-12  8:32   ` [PATCH v2 2/7] reftable/merged: allocation-less dropping of shadowed records Patrick Steinhardt
2024-02-12  8:32   ` [PATCH v2 3/7] reftable/merged: skip comparison for records of the same subiter Patrick Steinhardt
2024-02-12  8:32   ` [PATCH v2 4/7] reftable/pq: allocation-less comparison of entry keys Patrick Steinhardt
2024-02-12  8:32   ` [PATCH v2 5/7] reftable/block: swap buffers instead of copying Patrick Steinhardt
2024-02-12  8:32   ` Patrick Steinhardt [this message]
2024-02-12  8:32   ` [PATCH v2 7/7] reftable/reader: add comments to `table_iter_next()` Patrick Steinhardt
2024-02-12 17:19     ` Junio C Hamano
2024-02-13  6:57       ` Patrick Steinhardt

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=8c674915044c47c46c8e4efcb4d914fdd26e5c55.1707726654.git.ps@pks.im \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --cc=johncai86@gmail.com \
    --cc=sunshine@sunshineco.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;
as well as URLs for NNTP newsgroup(s).