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 1x29sZ-005cM3-2r for pgsql-hackers@arkaria.postgresql.org; Thu, 03 Sep 2026 16:01:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1x29sW-001I81-1I for pgsql-hackers@arkaria.postgresql.org; Thu, 03 Sep 2026 16:01:28 +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 1x29sW-001I7t-0D for pgsql-hackers@lists.postgresql.org; Thu, 03 Sep 2026 16:01:28 +0000 Received: from smtpout1.mo2.mail-out.ovh.net ([79.137.123.219]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1x29sS-00000002kcN-0Enj for pgsql-hackers@postgresql.org; Thu, 03 Sep 2026 16:01:27 +0000 Received: from director4.derp.mail-out.ovh.net (director4.derp.mail-out.ovh.net [79.137.60.37]) by mo2.mail-out.ovh.net (Postfix) with ESMTPS id 4hbPTs0xspz3xBT; Thu, 3 Sep 2026 16:01:20 +0000 (UTC) Received: from director4.derp.mail-out.ovh.net (director4.derp.mail-out.ovh.net. [127.0.0.1]) by director4.derp.mail-out.ovh.net (inspect_sender_mail_agent) with SMTP for ; Thu, 3 Sep 2026 16:01:20 +0000 (UTC) Received: from mta3.priv.ovhmail-u1.ea.mail.ovh.net (unknown [10.110.58.168]) by director4.derp.mail-out.ovh.net (Postfix) with ESMTPS id 4hbPTr4cZZz1xr2; Thu, 3 Sep 2026 16:01:20 +0000 (UTC) Received: from data-bene.io (unknown [10.1.6.7]) (Authenticated sender: ayoub.kazar@data-bene.io) by mta3.priv.ovhmail-u1.ea.mail.ovh.net (Postfix) with ESMTPSA id BBE40941B8A; Thu, 3 Sep 2026 16:01:18 +0000 (UTC) Authentication-Results: garm.ovh; auth=pass (GARM-98R00203bf6478-5116-4523-b7bc-82896e679c46, 0CB59451B420F26A041CA30BDF7A7AE1CB19FF1C) smtp.auth=ayoub.kazar@data-bene.io X-OVh-ClientIp: 105.105.184.198 Content-Type: multipart/alternative; boundary="------------xjx5KZl0MmB0lKwhWM6EfHmI" Message-ID: <777bc2f5-957e-4c8b-9f63-1d54e1f1bc3d@data-bene.io> Date: Thu, 3 Sep 2026 18:01:15 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Speed up COPY TO text/CSV parsing using SIMD To: KAZAR Ayoub , Nathan Bossart Cc: Andres Freund , Pg Hackers , Neil Conway , Manni Wood , Andrew Dunstan , Shinya Kato , Mark Wong , Nazir Bilal Yavuz References: Content-Language: en-US From: Ayoub Kazar In-Reply-To: x-ovh-tracer-id: 11083358685668671790 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: dmFkZTEkpLpLCuvtbKqyU32wPYKH9pCUNoTI4l5LVIHtnboPH0b3lILjuZV5gq92YqLnkoIuL1JTeOMX2irvKhJHCuWmgwTg9tok5R2sLatokxEUlCXVrBXyfIpKH8oo652dI825BhZ0dXoG/Bao+Kq0+/C5Y2RGsfHmJxmqj8uufQLbAOnCvSwrke0GG83MVK4uj3pDWPjZMO54C4wjagF5jjlWowWea81NfG8BBk1Nz5olyYyk9kF0583j/dngCrFl0vRH62JVW507nAMy9hrEQI9fKMXm3eXEAdozNCCD77RLn18r/95LZj+evvGRtNG+ItW4C7N0IWLTleh+UHL6TdnKf07deYtJNNs5G4p1rI12TjF4cM3lrfExGkF8lN9RRBAzVExIkGKmByZ1vPdQia8ydKfAPwmRUDJoTEOgjlfFwP97D+VFjY9DvZZ7zKJSdY8KA4tmHBGUj4l48LFvZJimPsQBOUKb54Rd3g+QBV+My01pTbbjTOwMICwu5mM6WPDne6PFFb/rTxN8Tt6vyn0EMUNCkisOkhCFH6NPfHIsfR0Xx0vo3t/RvB9Gj89EsAF7p2EV1Plvy9dRQgbl4Cawb97TvDzAe1dsdkcg3sDg3CHGNBsCMoQpSusQ9ZnP5CygmhxWqyiDPAJPIrXfnFB5zKmsokgYX0SqvcY61dA8tw List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------xjx5KZl0MmB0lKwhWM6EfHmI Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 02/04/2026 20:07, KAZAR Ayoub wrote: > On Tue, Mar 31, 2026 at 6:30 PM Nathan Bossart > wrote: > > On Fri, Mar 27, 2026 at 07:48:38PM +0100, KAZAR Ayoub wrote: > > I added a prescan loop inside the simd helpers trying to catch > special > > chars in sizeof(Vector8) characters, i measured how good is this at > > reducing the overhead of starting simd and exiting at first vector: > > the scalar loop is better than SIMD for one vector if it finds a > special > > character before 6th character, worst case is not a clean > vector, where the > > scalar loop needs 20 more cycles compared to SIMD. > > This helps mitigate the case of JSON(B) in CSV format, this is > why I only > > added this for CSV case only. > > Interesting. > > > In a benchmark with 10M early SIMD exit like the JSONB case, the > previous > > 3% regression is gone. > > While these are nice results, I think it's best that we target v20 > for this > patch so that we have more time to benchmark and explore edge cases. > > Thanks for the review. > Fair enough, I'll try many more cases in the upcoming weeks to make > sure we're not missing anything. > > > -- > nathan > > Regards, > Ayoub After looking into more test cases, the opportunity here isn't as big as it was for COPY FROM in general cases, yet i have seen good performance gains show up in most cases, and avoiding regressions elsewhere adds some complexity, there's also the possibility to include the case of TOASTed attributes here ; which i think is a win. I’ve marked the Commitfest entry as Withdrawn. Thanks to everyone for the reviews and feedback. If anyone else think we can still push this patch more forward, i'll take a look again. Regards, Ayoub --------------xjx5KZl0MmB0lKwhWM6EfHmI Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit


On 02/04/2026 20:07, KAZAR Ayoub wrote:
On Tue, Mar 31, 2026 at 6:30 PM Nathan Bossart <nathandbossart@gmail.com> wrote:
On Fri, Mar 27, 2026 at 07:48:38PM +0100, KAZAR Ayoub wrote:
> I added a prescan loop inside the simd helpers trying to catch special
> chars in sizeof(Vector8) characters, i measured how good is this at
> reducing the overhead of starting simd and exiting at first vector:
> the scalar loop is better than SIMD for one vector if it finds a special
> character before 6th character, worst case is not a clean vector, where the
> scalar loop needs 20 more cycles compared to SIMD.
> This helps mitigate the case of JSON(B) in CSV format, this is why I only
> added this for CSV case only.

Interesting.

> In a benchmark with 10M early SIMD exit like the JSONB case, the previous
> 3% regression is gone.

While these are nice results, I think it's best that we target v20 for this
patch so that we have more time to benchmark and explore edge cases.
Thanks for the review.
Fair enough, I'll try many more cases in the upcoming weeks to make sure we're not missing anything.

--
nathan
Regards,
Ayoub


After looking into more test cases, the opportunity here isn't as big as it was for COPY FROM in general cases, yet i have seen good performance gains show up in most cases, and avoiding regressions elsewhere adds some complexity, there's also the possibility to include the case of TOASTed attributes here ; which i think is a win.

I’ve marked the Commitfest entry as Withdrawn. Thanks to everyone for the reviews and feedback.

If anyone else think we can still push this patch more forward, i'll take a look again.


Regards,
Ayoub

--------------xjx5KZl0MmB0lKwhWM6EfHmI--