pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Nathan Bossart <nathandbossart@gmail.com>
To: Nazir Bilal Yavuz <byavuz81@gmail.com>
Cc: KAZAR Ayoub <ma_kazar@esi.dz>
Cc: Neil Conway <neil.conway@gmail.com>
Cc: Manni Wood <manni.wood@enterprisedb.com>
Cc: Andrew Dunstan <andrew@dunslane.net>
Cc: Shinya Kato <shinya11.kato@gmail.com>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Subject: Re: Speed up COPY FROM text/CSV parsing using SIMD
Date: Wed, 18 Feb 2026 15:26:14 -0600
Message-ID: <aZYudtuBLVb36pZE@nathan> (raw)
In-Reply-To: <CAN55FZ2OpqRxUUEvgPpHCk2HnY0xZSH1x09fgFGOUyXSv8HcEA@mail.gmail.com>
References: <CAN55FZ0FRB2OD6-oEESLvgUT4bLZQVD72pAqUqzdw7Rx5cN0ig@mail.gmail.com>
	<CA+K2Run1VdLnmp-5_Qv2Fax0KgT7LLJMH-uzjaaf-NZD1oU-=w@mail.gmail.com>
	<aYZdKSTw6N3khsVE@nathan>
	<CAN55FZ2DOeLjSXE2Jos99bgHG-Zeo3KjStrSgoA8Rf=2Mu+hFA@mail.gmail.com>
	<aYZvdsXPElQvwWOA@nathan>
	<CAN55FZ1=O6TjeZM2CUT7T2tu66uJT+w3G9FiRXVs+gt_ousFxQ@mail.gmail.com>
	<aY0FL4rXUl6ykn-a@nathan>
	<CAN55FZ3g6QaiC8G4GMjdJ24egvgc-HG_xpoOztxnM_wnQNn5aw@mail.gmail.com>
	<aY-vJe_ENCB-fux9@nathan>
	<CAN55FZ2OpqRxUUEvgPpHCk2HnY0xZSH1x09fgFGOUyXSv8HcEA@mail.gmail.com>

On Wed, Feb 18, 2026 at 04:38:07PM +0300, Nazir Bilal Yavuz wrote:
> By looking at these results having both is_csv and simd_enabled as an
> argument and sending them as constant boolean arguments help most.

Thanks for doing these tests.  ISTM we might as well get this initial
inlining stuff committed.  Thoughts?

-- 
nathan

Attachments:

v8-0001-Speedup-COPY-FROM-with-additional-function-inlini.patch (text/plain, 2.6K) download From 516176894a682e8bd4cb32202e3726f6621ba44d Mon Sep 17 00:00:00 2001 From: Nathan Bossart <nathan@postgresql.org> Date: Wed, 18 Feb 2026 14:55:39 -0600 Subject: [PATCH v8 1/1] Speedup COPY FROM with additional function inlining. Following the example set by commit 58a359e585, we can squeeze out a little more performance from COPY FROM (FORMAT {text,csv}) by forcing CopyReadLineText() to be inlined and by passing the is_csv parameter as a constant. This allows the compiler to emit specialized code with the known-const false comparisons and subsequent branches removed. Author: Nazir Bilal Yavuz <byavuz81@gmail.com> Reviewed-by: Ayoub Kazar <ma_kazar@esi.dz> Discussion: https://postgr.es/m/CAOzEurSW8cNr6TPKsjrstnPfhf4QyQqB4tnPXGGe8N4e_v7Jig%40mail.gmail.com --- src/backend/commands/copyfromparse.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/backend/commands/copyfromparse.c b/src/backend/commands/copyfromparse.c index 94d6f415a06..0aa549837b5 100644 --- a/src/backend/commands/copyfromparse.c +++ b/src/backend/commands/copyfromparse.c @@ -141,7 +141,8 @@ static const char BinarySignature[11] = "PGCOPY\n\377\r\n\0"; /* non-export function prototypes */ static bool CopyReadLine(CopyFromState cstate, bool is_csv); -static bool CopyReadLineText(CopyFromState cstate, bool is_csv); +static pg_attribute_always_inline bool CopyReadLineText(CopyFromState cstate, + bool is_csv); static int CopyReadAttributesText(CopyFromState cstate); static int CopyReadAttributesCSV(CopyFromState cstate); static Datum CopyReadBinaryAttribute(CopyFromState cstate, FmgrInfo *flinfo, @@ -1173,8 +1174,18 @@ CopyReadLine(CopyFromState cstate, bool is_csv) resetStringInfo(&cstate->line_buf); cstate->line_buf_valid = false; - /* Parse data and transfer into line_buf */ - result = CopyReadLineText(cstate, is_csv); + /* + * Parse data and transfer into line_buf. + * + * Because this is performance critical, we inline CopyReadLineText() and + * pass the boolean parameters as constants to allow the compiler to emit + * specialized code with the known-const false comparisons and subsequent + * branches removed. + */ + if (is_csv) + result = CopyReadLineText(cstate, true); + else + result = CopyReadLineText(cstate, false); if (result) { @@ -1241,7 +1252,7 @@ CopyReadLine(CopyFromState cstate, bool is_csv) /* * CopyReadLineText - inner loop of CopyReadLine for text mode */ -static bool +static pg_attribute_always_inline bool CopyReadLineText(CopyFromState cstate, bool is_csv) { char *copy_input_buf; -- 2.50.1 (Apple Git-155)

view thread (178+ messages)  latest in thread

Message-ID: <aZYudtuBLVb36pZE@nathan>
Permalink:  ../aZYudtuBLVb36pZE@nathan/
Also on:    postgresql.org/message-id/aZYudtuBLVb36pZE@nathan

 ·  · 

reply

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: nathandbossart@gmail.com, byavuz81@gmail.com, ma_kazar@esi.dz, neil.conway@gmail.com, manni.wood@enterprisedb.com, andrew@dunslane.net, shinya11.kato@gmail.com
  Subject: Re: Speed up COPY FROM text/CSV parsing using SIMD
  In-Reply-To: <aZYudtuBLVb36pZE@nathan>
  References: <CAN55FZ0FRB2OD6-oEESLvgUT4bLZQVD72pAqUqzdw7Rx5cN0ig@mail.gmail.com> <CA+K2Run1VdLnmp-5_Qv2Fax0KgT7LLJMH-uzjaaf-NZD1oU-=w@mail.gmail.com> <aYZdKSTw6N3khsVE@nathan> <CAN55FZ2DOeLjSXE2Jos99bgHG-Zeo3KjStrSgoA8Rf=2Mu+hFA@mail.gmail.com> <aYZvdsXPElQvwWOA@nathan> <CAN55FZ1=O6TjeZM2CUT7T2tu66uJT+w3G9FiRXVs+gt_ousFxQ@mail.gmail.com> <aY0FL4rXUl6ykn-a@nathan> <CAN55FZ3g6QaiC8G4GMjdJ24egvgc-HG_xpoOztxnM_wnQNn5aw@mail.gmail.com> <aY-vJe_ENCB-fux9@nathan> <CAN55FZ2OpqRxUUEvgPpHCk2HnY0xZSH1x09fgFGOUyXSv8HcEA@mail.gmail.com> <aZYudtuBLVb36pZE@nathan>

* 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