Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x3t52-006jo7-2k for pgsql-hackers@arkaria.postgresql.org; Tue, 08 Sep 2026 10:29:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1x3t51-006PMj-2X for pgsql-hackers@arkaria.postgresql.org; Tue, 08 Sep 2026 10:29:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x3t51-006PMb-1M for pgsql-hackers@lists.postgresql.org; Tue, 08 Sep 2026 10:29:31 +0000 Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1x3t4y-00000003Yq6-3sBh for pgsql-hackers@postgresql.org; Tue, 08 Sep 2026 10:29:31 +0000 Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-6a642495d81so6497231a12.2 for ; Tue, 08 Sep 2026 03:29:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=planetscale.com; s=google; t=1788863368; x=1789468168; darn=postgresql.org; h=content-transfer-encoding:content-type:in-reply-to:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to:content-type; bh=GCBc5oTkt5TiV9w66VW9P3wdWOF1BV8A4LD03RPZXIk=; b=DEkNDCXOcaYaNliHmHskYmhaBTDCF5tqrfUFqiNGkJi1DM0xl+ZQf1nzoVmd0JxSvD 9cWt9F4Dz5x8dUKEKzXZWtS0Yvpg43LVFQi6G0j3vRdS4nItGmU9IkCoDyt1WvUvrZ4b 32hFZkTF9t7EqwM9ITvLWgEc7QHgRXXJqOaYizTcMMDCa9OQ93BCLqnu1phKWIenHPE/ g7slm1xrnWUYtHTuwvac4D6g9e07iqa2TmEbS3NdMzhNuXFTeIb1W2gaBcF2ZVgCLDjg ZvxNwD+TWEjqYii5zUF8KIhEqD+1IcxSAsPXB3Uvl0j0S0E2ktrjFPX3tNjufcDyY7YB FCUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788863368; x=1789468168; h=content-transfer-encoding:content-type:in-reply-to:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=GCBc5oTkt5TiV9w66VW9P3wdWOF1BV8A4LD03RPZXIk=; b=DgAQZEC9Pr+MD2mZb3j0/ZDRKzPPFNEjhD9BiIga7E1FpPXbMOMUe41ZJDn3YayZR7 L13mTtpyyVqEo1MO/GwgTh2+jDkyKvzuH9pSBqu+mk20ixnAYX1zzZwz6rYICS9EEg4P UnFx5sa7tDdrpqT+LAMjkv/ac7cB4oQiArIuDUEejPVA9ETImmOpijzhNmOsbxS0znpG zrhCRiAgLJw8BK6zXaNYnhtgFQi1yZAKLRbGWOHVggxqp0jWmiXXbgUCYGg5pj6eK2HK 402b+VTErDXGhLzHtc8pU/kNmDqoijYhtn9klVDwtAiKc8kGSgenJJSiExMYmwqklDC7 AsjA== X-Forwarded-Encrypted: i=1; AKwUvBziIe8Gumu+5uvFkaISa9Bafepr96XdmLgUEnUgGDqGEJVUx0tQ7QpeLqo22HOUWgan9WawjK+4bUKJXJq3@postgresql.org X-Gm-Message-State: AFuF++kz9jZWKqPnDpeabo+un/cXCRJx0x+imimM+m5NhH3efAG894hu hu4gNnfy/c3JD5jFhuYGUmqTUuS4ZbKuSeN6U3fEwaR1U5URQ6pnnG4FBQ1FZ59ssQc= X-Gm-Gg: AYBFou2NT6z49CJu+2dTC9nH66LvmIZJEepRMXpqVJ8bSjcTeuiUponlXXFWw/Lo4re /gQ2jIwsNwrO5IK7prxoXd9gh9KzzEzhAOoibXGaw5WNzVr/Z4k/ZrWb7SAoxuf+deq5DoX65Rt xOBa0bBQWZsotpvZ2b52dFhooGqOTAL7GIcxClYsETpFu/KzXvRqo00zh/cdzdT7+vfn2UlT2Py Omzqq8B1/eMLe4BVMoJ6D/v8AoGFmh1sKtPLgLOpUoWkYJOLX4GS1VpoXJz3bJtnGDa4gZ3q/xl SiCi1C4dmvU57W0Qfa7pRmno6FrJDFN7qPF7t5e5EGmGL1QfvU0MXe/pEOPDbxiQ1ApNIw0SAOw 95NRlwczwCmcY1a1XBew6UfKp+AXCFi7Nh8gethB35jyfNmk3Pouj5ymMS05oS0CFM5Kh/18Jn2 W6PPlFGgxsYD1B1z7bYBoddd7DoC+0dJoRNADky3UTBXA8g05hgRpjzBOfW/4HrK+lcMgjzJp97 4ENPnwV2BRjr0F0HZlScOI2flXzbbWC+uzSWGJmgxzLe9GMAppItfLaug== X-Received: by 2002:a05:6402:13d2:b0:6a6:1a05:8b27 with SMTP id 4fb4d7f45d1cf-6a7e8d6c5d5mr9419677a12.8.1788863367333; Tue, 08 Sep 2026 03:29:27 -0700 (PDT) Received: from ?IPV6:2a04:4540:6550:7800:caa:dcba:a022:69de? ([2a04:4540:6550:7800:caa:dcba:a022:69de]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6a7e68a6e0esm5501436a12.9.2026.09.08.03.29.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 08 Sep 2026 03:29:27 -0700 (PDT) Message-ID: <1fe7eff1-b402-48b0-a1d1-48e5e79f8df7@planetscale.com> Date: Tue, 8 Sep 2026 12:29:26 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: =?UTF-8?B?UmU6IFJl77yaW1BBVENIXSBTcGVlZCB1cCByZXBlYXQoKSBmb3IgbGFy?= =?UTF-8?Q?ger_counts?= From: Jan Nidzwetzki To: ChenhuiMo , pgsql-hackers Cc: "jeevan.chalke" , Heikki Linnakangas References: <710c312b-2caf-4526-8950-8e0e504be2c1@planetscale.com> Content-Language: en-GB In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello Chenhui, I tried to find the reason why the preferred cap in the benchmark differs so much between our machines, and I came up with a theory that explains the behavior. On 04.09.26 15:51, Jan Nidzwetzki wrote: > The preferred cap on the J5005 is the first one at or above this > threshold (0x100000 = 1 MB). Does this match the behavior on your > systems as well? glibc tunable ============= On x86, glibc switches memcpy() to non-temporal stores above x86_non_temporal_threshold (bypassing the CPU caches and writing data directly to the system memory). This value is dynamically calculated based on the characteristics of the machine. However, it can be adjusted manually, like: GLIBC_TUNABLES="glibc.cpu.x86_non_temporal_threshold=$value\ :glibc.cpu.x86_memset_non_temporal_threshold=$value" I did an experiment (outside of PostgreSQL) where I forced certain thresholds and repeated the benchmark. Changing that value moves the preferred cap with it. On the J5005, with a 256 MB output: set threshold 1 KB source 100 B source 64 KB cap64k cap64k 256 KB cap256k cap256k 1 MB cap1m cap1m 4 MB none none disabled none none The speedup always starts at the first cap at or above the threshold, when non-temporal stores are used and the cache is bypassed. At a 4 MB threshold, the effect disappears entirely. A 4 MB block is the whole L2 on this machine, so no size is both large enough for non-temporal stores and small enough to stay cached. With the non-temporal path disabled, the row is flat as well, and uncapped doubling falls below the current implementation. Since this is adjustable through GLIBC_TUNABLES, the best cap is not only machine-dependent; it is settable from the environment. We could potentially use something like __builtin_nontemporal_store() to avoid the glibc threshold and force non-temporal stores. However, this is compiler- and architecture-specific, and I don't think it is worth optimizing this particular code path that way. What do you think about the theory? Personally, I would go with the early return and memset() optimization as outlined in my last mail, since they show clear improvements in all tested environments. The doubling / capping approach shows good results in many situations, but is harder to implement, since picking a wrong cap leads to regressions. However, I am still curious what other people will see when they repeat the benchmarks. Best regards Jan -- Jan Nidzwetzki PlanetScale Postgres Core Team