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 1vzdQI-001BGt-0t for pgsql-hackers@arkaria.postgresql.org; Mon, 09 Mar 2026 16:25:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vzdQE-00HQRF-1Y for pgsql-hackers@arkaria.postgresql.org; Mon, 09 Mar 2026 16:25:34 +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 1vzdQE-00HQR7-0W for pgsql-hackers@lists.postgresql.org; Mon, 09 Mar 2026 16:25:34 +0000 Received: from mail-dy1-x132d.google.com ([2607:f8b0:4864:20::132d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vzdQB-00000001pDS-3uM1 for pgsql-hackers@postgresql.org; Mon, 09 Mar 2026 16:25:34 +0000 Received: by mail-dy1-x132d.google.com with SMTP id 5a478bee46e88-2be26d11b95so10488522eec.0 for ; Mon, 09 Mar 2026 09:25:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1773073530; cv=none; d=google.com; s=arc-20240605; b=QM4xzQVCXGSn9SMQD+VzvsL0VOSVcxV6/CBajNoAFNQKXB1zRdizaxxbWJW2MHu4Fz 1nc7TQr2vp6mF8GLRQJtuRP54TSTLJN0lC4IjWHsF2bzvRbGORFZsiZrX8RHf61NEZBW AGILWwTl8wGC2yM8Ii7WGDL6oqK12tDMrgnhqAY2IrqtGTllk8dlQdSg8ZrN4fU1gcWd pJwuSwgqmVKdZkWtM3KVPtEh/DHoszkP4SzIqHxC4ob5rDjDHfqsZCbY8IAWB0n0Aywy jf9/7ujlek8H1By8NcpWv7DYDCn6BYd6oZxX+U8Dz2bYN0A3bPt9yZAy4GXz5cJYbSxI rMdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=HpEo7y9bbHFGjYyjpT5DclLbtOKl7NiWXiQJEnXeVBo=; fh=BawSWetgE9wsa7rjWUMyEEUS/e58KHEh4Qu390NnxeE=; b=IXtK8xUxwj+wLx9TMwf7R79aV5O1SXlRkDrjwCn2CzvAMjA6REBDPkAXgRuZXxYsjl x9AqSrhc0FrVxcD7/iKkaenjAvx8tMDgbFhOHYHKIR9Dp+dcdXLQhVyZ3xmal5cYFHT+ zghitVJOgii2wbDa30oQlga9eMfS14dXrXi7LYsYStwN6Qz2nHz2+kxYosP8FuKCrhU5 X7bzP6R8GDCoLvpTnLyh37XCfsVCgtyH2c1UK4I9Q6lD315xnqb0C3Q+od/TNterNVqP d7SUa4qDxpif9/CBRCZhFeOowGliqIqSOt/BpoPelkDkXvBtRgATmzvd92pY0cArOZMh 9fRA==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773073530; x=1773678330; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=HpEo7y9bbHFGjYyjpT5DclLbtOKl7NiWXiQJEnXeVBo=; b=cudShZcnOXSF+Bw4TpLkMWFVYt1KRzHbp1CgC7lEr7UhGQzJLAdswmiUDA0xqXb2e6 4+g3WHiZ4pVPOLxmy4PGjDbOIko2qxHfE52i7MtuQUDXqq9JKscIjM6uPXq0I3GhXoKZ GQ79vSM4g/6oYhfWZ6Na/a+Q+OQKHWINSCs08XWWRrUfyHf9OcVsrIh6oEYv/309AZxm 1TlXdlEgq962C6Jnu5sdBVYBTa6jiQJwzeWf3L1Omc7cSzsNh1pzvczfSCjxCiffQANA E4MrAb2DbvALK3nm1CjF/slz92mI/jc4121wyjZQprqnapEzzHgoTu2pfw7gkUWvCv73 68Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773073530; x=1773678330; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=HpEo7y9bbHFGjYyjpT5DclLbtOKl7NiWXiQJEnXeVBo=; b=dfL3e48qeKeA1Fs4rOAf+t3hYcypUhcbEoc/8cHuD69L+eRPZfN4O35pptIDfAodWm EMJvmBgXFOmnTHGeJEYGiuc4YB11E9lL6CwdD2QxUM326288S1ralG/chNfYyJj3QQ8y QIzzvykoOElCTOyiPCF+l5QaR2ORqTOLeeifd6Xe/C2zTSv8JO/mwya2bKkz+CQM0B/g g2ewfa+I56CMOu2BQ1fvd0YCt50w3OtwMwKcNjsSum6NVNo2h+msZ4y46KIF3kfkeDAj d1rbb5HGOpmYVIKoThTz8L0wgvkfAbCD7eqhrOlDyueQoO9xJPJbCf+whLoRfqJN4kdP /afw== X-Gm-Message-State: AOJu0YxdNHGTjp5+D/ya6DQIzEovqZXlXgCBJcOTPkyxkUCHevuDdtdY pqTq3GHGXDJh/00lQRYntVhYHtm69SkajoFsovLHVsUCU+nf+AUkbXT9XHaOSSNFGORSu4qxe31 aeAdtpf9XXlyvonmwOnQ57/QQ+G7wFnE= X-Gm-Gg: ATEYQzwbro9wSU2kLijqj68y68ElvRveKSo791ubyc0FjUM8hl1mkyjFf6Ura6ZB/fH p5lk05L1lWZDfljClOWkrg0E40FckgWd7b8BeQsI8WxQvrxS5ldD8wRblNVROYTqlvKJsp1a3Rj 3gsMKPGb8A+Tosls2T/X4J1i/BlMS8MKoT9YomxNvXeRNM84GkxoB1Em8QGYREGy6WYzaaBcZlu IA8YfEeBbXcJEgJoiL1uVQWbbhNh3jx2yeszuJSWnBx1MRiwkV1pZhOQSyyDZhQ2xwrVAj/skap JGkjGMA= X-Received: by 2002:a05:7301:1010:b0:2be:2b8d:399b with SMTP id 5a478bee46e88-2be4de90f09mr3021080eec.5.1773073529630; Mon, 09 Mar 2026 09:25:29 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Ranier Vilela Date: Mon, 9 Mar 2026 13:25:20 -0300 X-Gm-Features: AaiRm50DLsPKwdBGw8V0_BPeN8ICrER8O6Lfs7NyrKoeDliM-bFiS1vRzRjy1JU Message-ID: Subject: Re: Avoid multiple calls to memcpy (src/backend/access/index/genam.c) To: Bryan Green Cc: Pg Hackers Content-Type: multipart/alternative; boundary="000000000000e4f389064c99d96f" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000e4f389064c99d96f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Em seg., 9 de mar. de 2026 =C3=A0s 11:47, Bryan Green escreveu: > I created an example that is a little bit closer to the actual code and > changed the compiler from C++ to C. > > It is interesting the optimization that the compiler has chosen for > version 1 versus version 2. One calls > memcpy and one doesn't. There is a good chance the inlining of memcpy as > SSE+scalar per iteration > will be faster for syscache scans-- which I believe are usually small (1-= 4 > keys?). > I doubt the inline version is better. Clang is supported too and the code generated is much better with memcpy one call outside of the loop. > > Probably the only reason to do this patch would be if N is normally large > or if this is considered an > improvement in code clarity without a detrimental impact on small N > syscache scans. > I realize you only said "possible small optimization". It might be > worthwhile to benchmark the code for > different values of n to determine if there is a tipping point either way= ? > In your opinion, shouldn't this be considered an optimization, even a small one? best regards, Ranier Vilela --000000000000e4f389064c99d96f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


Em seg., 9 de m= ar. de 2026 =C3=A0s 11:47, Bryan Green <dbryan.green@gmail.com> escreveu:
I created an example th= at is a little bit closer to the actual code and changed the compiler from = C++ to C.=C2=A0

It is interesting the optimization that = the compiler has chosen for version 1 versus version 2.=C2=A0 One calls
memcpy and one doesn't.=C2=A0 There is a good chance the inlinin= g of memcpy as SSE+scalar per iteration
will be faster for syscac= he scans-- which I believe are usually small (1-4 keys?).=C2=A0=C2=A0
=
I doubt the inline version is better.
Cla= ng is supported too and the code generated is much better with memcpy one c= all outside of the loop.
=C2=A0

Probably the onl= y reason to do this patch would be if N is normally large or if this is con= sidered an
improvement in code clarity without a detrimental=C2= =A0impact on small N syscache scans.=C2=A0=C2=A0
I realize you on= ly said "possible small optimization".=C2=A0 It might be worthwhi= le to benchmark the code for=C2=A0
different values of n to deter= mine if there is a tipping point either way?
= =C2=A0In your opinion, shouldn't this be considered an optimization, ev= en a small one?

best regards,
Ranier Vil= ela
--000000000000e4f389064c99d96f--