From: Patrick Steinhardt <ps@pks.im>
To: Kristofer Karlsson via GitGitGadget <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Johannes Sixt <j6t@kdbg.org>,
Kristofer Karlsson <krka@spotify.com>
Subject: Re: [PATCH v2 1/2] t: add "test-tool genbytes" to avoid slow tr(1) on macOS
Date: Mon, 9 Nov 2026 07:59:44 +0100 [thread overview]
Message-ID: <avFvYD5K4SKlveiI@pks.im> (raw)
In-Reply-To: <54139a3a97127732e11fc5abbc9a3687542669f6.1794165304.git.gitgitgadget@gmail.com>
On Sun, Nov 08, 2026 at 07:15:03PM +0000, Kristofer Karlsson via GitGitGadget wrote:
[snip]
> This makes t4205 much faster on macOS in CI. The Linux jobs, shown
> for comparison, only save the few seconds that GNU tr(1) took, which
> is within the usual noise:
>
> job before after change
> osx-gcc 821.1s 243.3s -70.4%
> osx-reftable 911.0s 194.0s -78.7%
> linux-asan-ubsan 226.7s 222.1s -2.0%
> linux-leaks 320.2s 298.8s -6.7%
Nice improvement.
> diff --git a/t/helper/test-genbytes.c b/t/helper/test-genbytes.c
> new file mode 100644
> index 0000000000..b760326b24
> --- /dev/null
> +++ b/t/helper/test-genbytes.c
> @@ -0,0 +1,61 @@
Okay. The diff is unfortunately quite useless as we do the file rename
plus all the changes in a single step. It might've been helpful to split
this up into:
1. A rename of the file.
2. A refactoring of `cmd_genzeros()` to use the write buffer.
3. A change to introduce `cmd_genbytes()`.
But maybe I'm also overdoing this.
> +#define DISABLE_SIGN_COMPARE_WARNINGS
> +
> +#include "test-tool.h"
> +#include "git-compat-util.h"
> +#include "hex-ll.h"
> +
> +/*
> + * Write "count" copies of "byte" to stdout, or an endless stream of them if
> + * "count" is negative.
> + */
> +static int generate_bytes(char byte, intmax_t count)
> +{
> + char buf[256 * 1024];
> + ssize_t n;
> +
> + memset(buf, byte, sizeof(buf));
> +
> + /* Writing out individual bytes is slow... */
> + while (count < 0)
> + if (xwrite(1, buf, ARRAY_SIZE(buf)) < 0)
> + die_errno("write error");
> +
> + while (count > 0) {
> + n = xwrite(1, buf,
> + count < ARRAY_SIZE(buf)
> + ? count : ARRAY_SIZE(buf));
> +
> + if (n < 0)
> + die_errno("write error");
> +
> + count -= n;
> + }
Okay. These two loops are a bit ugly if you ask me, but they are carried
over from preexisting code. So this is good enough.
> + return 0;
> +}
> +
> +static intmax_t parse_count(int argc, const char **argv, int pos)
> +{
> + return pos < argc ? strtoimax(argv[pos], NULL, 0) : -1;
> +}
We can use `git_parse_signed()` instead.
> diff --git a/t/t0613-reftable-write-options.sh b/t/t0613-reftable-write-options.sh
> index 0b27d75fe3..b2032a799d 100755
> --- a/t/t0613-reftable-write-options.sh
> +++ b/t/t0613-reftable-write-options.sh
> @@ -146,7 +146,7 @@ test_expect_success 'small block size fails with large reflog message' '
> (
> cd repo &&
> test_commit A &&
> - test-tool genzeros 500 | tr "\000" "a" >logmsg &&
> + test-tool genbytes 61 500 >logmsg &&
> cat >expect <<-EOF &&
> fatal: update_ref failed for ref ${SQ}refs/heads/logme${SQ}: reftable: transaction failure: entry too large
> EOF
I wonder about the regression in readability though. Maybe that's just
me, but I don't happen to know all ASCII values by heart, so if I were
to read this I would now wonder what's so special about 61. And the next
thing to wonder about is whether this is supposed to encode "=" (decimal
61) or "a" (hexadecimal 61), and without reading the code of genbytes I
would not be able to tell.
So can we maybe make the underpinning logic a bit more intelligent, e.g.
by accepting "\NNN" or "\xNN" syntax instead of two hex characters? That
might also make it more extensible going forward if the next developer
wants to make genbytes take and repeat strings of arbitrary length
as-is.
Patrick
next prev parent reply other threads:[~2026-11-09 6:59 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-07 14:59 [PATCH 0/3] t: add "test-tool genbytes" to avoid slow tr(1) on macOS Kristofer Karlsson via GitGitGadget
2026-11-07 14:59 ` [PATCH 1/3] t/helper: rename test-genzeros.c to test-genbytes.c Kristofer Karlsson via GitGitGadget
2026-11-07 23:15 ` Junio C Hamano
2026-11-08 4:44 ` Junio C Hamano
2026-11-08 9:10 ` Kristofer Karlsson
2026-11-08 18:35 ` Junio C Hamano
2026-11-08 19:10 ` Kristofer Karlsson
2026-11-07 14:59 ` [PATCH 2/3] t: add "test-tool genbytes" to avoid slow tr(1) on macOS Kristofer Karlsson via GitGitGadget
2026-11-08 8:54 ` Johannes Sixt
2026-11-08 9:18 ` Kristofer Karlsson
2026-11-08 9:35 ` Johannes Sixt
2026-11-08 12:24 ` Kristofer Karlsson
2026-11-08 16:34 ` Johannes Sixt
2026-11-09 9:33 ` Johannes Sixt
2026-11-09 13:05 ` Kristofer Karlsson
2026-11-09 15:38 ` Johannes Sixt
2026-11-10 6:00 ` Collin Funk
2026-11-10 8:09 ` Kristofer Karlsson
2026-11-08 18:37 ` Junio C Hamano
2026-11-07 14:59 ` [PATCH 3/3] t: replace "test-tool genzeros" with "genbytes NUL" Kristofer Karlsson via GitGitGadget
2026-11-07 23:04 ` [PATCH 0/3] t: add "test-tool genbytes" to avoid slow tr(1) on macOS Junio C Hamano
2026-11-08 9:11 ` Kristofer Karlsson
2026-11-07 23:23 ` Junio C Hamano
2026-11-08 9:13 ` Kristofer Karlsson
2026-11-08 19:15 ` [PATCH v2 0/2] " Kristofer Karlsson via GitGitGadget
2026-11-08 19:15 ` [PATCH v2 1/2] " Kristofer Karlsson via GitGitGadget
2026-11-09 1:39 ` Junio C Hamano
2026-11-09 7:10 ` Kristofer Karlsson
2026-11-09 15:41 ` Junio C Hamano
2026-11-09 6:59 ` Patrick Steinhardt [this message]
2026-11-09 7:43 ` Kristofer Karlsson
2026-11-08 19:15 ` [PATCH v2 2/2] t: replace "test-tool genzeros" with "genbytes 00" Kristofer Karlsson via GitGitGadget
2026-11-10 18:26 ` [PATCH v3] t: add "test-tool genbytes" to avoid slow tr(1) on macOS Kristofer Karlsson via GitGitGadget
2026-11-10 19:31 ` Junio C Hamano
2026-11-11 10:54 ` Patrick Steinhardt
2026-11-11 15:38 ` Junio C Hamano
2026-11-11 15:47 ` Kristofer Karlsson
2026-11-11 17:57 ` Junio C Hamano
2026-11-11 15:59 ` [PATCH v4] " Kristofer Karlsson via GitGitGadget
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=avFvYD5K4SKlveiI@pks.im \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=j6t@kdbg.org \
--cc=krka@spotify.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