From: Jan Nidzwetzki <jan@planetscale.com>
To: ChenhuiMo <chenhuimo.mch@qq.com>
To: pgsql-hackers <pgsql-hackers@postgresql.org>
Cc: Jeevan Chalke <jeevan.chalke@enterprisedb.com>
Cc: Heikki Linnakangas <hlinnaka@iki.fi>
Subject: Re: [PATCH] Speed up repeat() for larger counts
Date: Mon, 14 Sep 2026 12:13:46 +0200
Message-ID: <01612e7c-ac8c-45ad-9739-c13675cfd3e5@planetscale.com> (raw)
In-Reply-To: <tencent_304AEAD3F7F0731305E2B69429CC1A72E506@qq.com>
References: <tencent_C5BBECF985A270FBC49463EDAF722CD5E005@qq.com>
<tencent_87198B026B9BD4F4664DA3F226D5E47BE905@qq.com>
<710c312b-2caf-4526-8950-8e0e504be2c1@planetscale.com>
<tencent_902E15E89BF9D99242653BC714600DA2D205@qq.com>
<fc35e9a4-09c0-4220-8f6d-3cc371c980c3@planetscale.com>
<1fe7eff1-b402-48b0-a1d1-48e5e79f8df7@planetscale.com>
<tencent_304AEAD3F7F0731305E2B69429CC1A72E506@qq.com>
Hi Chenhui,
Thanks for the new version and for splitting the patch set. It applies
to the current master branch, and check-world passes.
On 12.09.26 15:12, ChenhuiMo wrote:
[...]
> Here the non-temporal threshold is 12.625 MiB, so the first tested cap
> at or above it is 16 MiB. This also matches the earlier measurements,
> where cap16m was often the best choice for the larger-output cases.
>
> So the glibc non-temporal threshold appears to correlate well with the
> preferred cap on both of my x86 systems.
That settles it for me. Collecting the three x86 systems measured so far:
system non-temporal threshold first cap at or above it
J5005 1 MiB cap1m
i5-13500H 1.3125 MiB cap2m
i9-12900H 12.625 MiB cap16m
In every case, the preferred cap is the first one at or above the
threshold. So the 64 KB to 16 MB spread we started with is a glibc
setting with three different values, not a hardware property.
Review
======
In patch 2, CHECK_FOR_INTERRUPTS() is called after memset(). Usually,
CHECK_FOR_INTERRUPTS() is called periodically to check whether a
long-running task has to be aborted. After memset() returns, the actual
heavy work is already done. Not sure if we actually need the check.
In addition, I recommend a short comment for the new 'if (slen == 1)'
path that describes that memset() is faster than the loop below.
strings.sql offers only partial test coverage for the added conditions.
I recommend adding at least these three tests to the existing ones to
test the early return and the memset() fast path:
SELECT repeat('', 10);
SELECT repeat('x', 0);
SELECT repeat('x', 4);
Additional comments
===================
Your new patch set has a different author than the previous ones. Please
double-check that it contains the actual name you want visible in the
commit.
When you generate a new patch set, it is common to version it to make it
easier for others to understand which version is most recent. You can do
this by specifying the "-v" option when exporting the patch. For
example, "git format-patch -v3 -2" generates version 3 of the patch
series consisting of the last two commits.
Best regards
Jan
--
Jan Nidzwetzki
PlanetScale Postgres Core Team
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: jan@planetscale.com, chenhuimo.mch@qq.com, jeevan.chalke@enterprisedb.com, hlinnaka@iki.fi
Subject: Re: [PATCH] Speed up repeat() for larger counts
In-Reply-To: <01612e7c-ac8c-45ad-9739-c13675cfd3e5@planetscale.com>
References: <tencent_C5BBECF985A270FBC49463EDAF722CD5E005@qq.com> <tencent_87198B026B9BD4F4664DA3F226D5E47BE905@qq.com> <710c312b-2caf-4526-8950-8e0e504be2c1@planetscale.com> <tencent_902E15E89BF9D99242653BC714600DA2D205@qq.com> <fc35e9a4-09c0-4220-8f6d-3cc371c980c3@planetscale.com> <1fe7eff1-b402-48b0-a1d1-48e5e79f8df7@planetscale.com> <tencent_304AEAD3F7F0731305E2B69429CC1A72E506@qq.com> <01612e7c-ac8c-45ad-9739-c13675cfd3e5@planetscale.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox