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 1vmukn-0007Pv-0s for pgsql-hackers@arkaria.postgresql.org; Mon, 02 Feb 2026 14:18:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vmukl-00EC63-0t for pgsql-hackers@arkaria.postgresql.org; Mon, 02 Feb 2026 14:18:12 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vmukk-00EC5v-2o for pgsql-hackers@lists.postgresql.org; Mon, 02 Feb 2026 14:18:11 +0000 Received: from mail-dl1-x122c.google.com ([2607:f8b0:4864:20::122c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vmuki-00000000CaV-3ykL for pgsql-hackers@postgresql.org; Mon, 02 Feb 2026 14:18:10 +0000 Received: by mail-dl1-x122c.google.com with SMTP id a92af1059eb24-124a95e592fso5104154c88.0 for ; Mon, 02 Feb 2026 06:18:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1770041888; cv=none; d=google.com; s=arc-20240605; b=ciKf6iQKxJRhL7oaYRWQ0yMKY9kBevRcPs1c9SQwsWIQPBiXvJ7CzZ7MSQPFhrrji9 7U9ZBdBBm1HaLZ6U2GinAD4sBKKw964+E5UAJLnbp9N1hJT9sPQpT7WtaB+9y8vbaq1N L6JXE1P4GeabeX7XXAKMuzC6rAio2CWpwe1vAyrXuNQBBKip9UFoN7UGj5dp1wuQYiwJ sDUEkMDCMXlLgxHu0uWrE+d30BmKAgCxiWghfkEk/lFHQ50yMk3Z59UPxMpjM4aECSss ynzpsYOZElpFcPqiUQD/4GdIJAGrS10lT9MKdTfycjLObAJZQrXtcxAGJKcRgRDy1Mms 45Kg== 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=02dZKnjjznv1nJLD69E4Hopq0x4tpmlYHgZ67QcRlAQ=; fh=5FVJRgSiKzQTmXdfr8HUU5MpuPOx9fadJ4jTpQRNFKk=; b=hOrdIB/hcX9WCb6XbsLqFZgZ7HTUpT75NBVlDnCnsne45LE5RsuidKzNYCMScfpNAp 3CvvB4SUJiN357gRo3Zf0YgXuy6ZvkRz0CP8TltRLLHMifV8LmM1E38+BTNAXOmEd70+ jl12A7bIiLwIsd0t87OmOXTF9CDLAWrSpJC13cSJryhwCFYxhotX9ARxF3BpJywrFO7H PcAax35xy8JIh9nl2VMfxj317BfDtEKU+AAeRvQn4DsNMBwwUSsZK01bOmsPxZMkZour XIC17a/p93nZhM9WsK7KkRr/eMxL1kvTLuso43RKVQtX4FSoutPh3vtwjGsRJbkjbo+p K9+A==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1770041888; x=1770646688; 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=02dZKnjjznv1nJLD69E4Hopq0x4tpmlYHgZ67QcRlAQ=; b=U3NAOgdJxZKTZT2AMGa+Ydvy6F0WUoQlqHERNCCvLL/AR3He9gXKK1hUaNco6p8nbo VRhjnj5hT3Hz275xMGgJbaAtVyoqaysVDDQbwjc3CNtZntpAcu+/ygpTy4Fi6/tnNZIb 2VDtnqskeKCv7yi027FyMUeVv6LmHnLAusTnByNn/tU/jXiraMZ47tmsKH6EjMXiNQWu bW235IKGn8Tzo2S5KnefhfWPEsz/wFQWlJ259iLs3fA/chAMFjnNqKHsbqvY1fr8h4qv YmFJ2N+a4bHv7i2yTSUBIajeClJiore/ZUiBdGIHTLLba1rck2ocL8sTkbPsl+he0Q9F y+QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770041888; x=1770646688; 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=02dZKnjjznv1nJLD69E4Hopq0x4tpmlYHgZ67QcRlAQ=; b=KysxkDUpPmF3GMUJj4Bq1xNxiw8bz/4XZ+CB/9vnoRkdt6SK/NXA1HWYSyt4Xt6daM KJJSWhSkssdOaBUVXuBUQY3+85SglAC7UmMuwQ/dkdoS2DdyX5Lgq3MwkK192xeV2zsW Gut9hK5I6dk3t5HEPVapXyVuIERcUILPfqQKkgLqjuAHdJyBefsMUstyvwnX2Fn03FAS p8KUxkYk7b6vHztD+erjOWxeHFnzlnAR88dvtS+OTSVQ+3YpzFIiA8n+vViBh5XtCG+0 OXU9fdfpt1YhOKR5KFzn7MmC8z/UH8P/zs5n2nR+ozHdWdKwHQHkBNlx7zSOHZTkUUbZ I1xQ== X-Forwarded-Encrypted: i=1; AJvYcCXQo/STRxC4bGQ/HxBAiLGYQ9tQhvP44l5VbXcat+gepPW5SERHgjHbUI+i6/PgcsqwIB/iElrN5+btm/2e@postgresql.org X-Gm-Message-State: AOJu0YwuWketm+a8xzy798/p8NCJX+ozV/tiy9WPzpK+TVyvHRnGEz0w 2jqj8YIFC2XwiFjmAvwBnXgzASJdVglYHVIO/qUwqk4Qn1mZhZkAN0ARHMtaO54kj368d+FYEQo lT9yGaAzCEE5goepBQ8YhrQz81jpuVsEv/dQNKie1 X-Gm-Gg: AZuq6aINyujZvcTss+3fJq9FHb1VeesznbGWkGUzR5hXy66aJP6SVLEk8dmK4xDmDp8 RzHaM1gBAY0TDgm3b6FlGHU0u9MabWb6S0FZFUF7FhuI4QWWYH36Ps42Xdch/+nL6wYXpd6LWM9 oYfsYhFH0Gs+ZTKlbhhKjkBkV34FnH4iiRULWi3uSEVGkLRMBBXcbFEPr13GC+nQocJ+lX4ObcU vlrjK3lqbkdnvUHtFMG23gS67d61ZoH/WmgWAoj7yzbAPUDUIbwkOwrmfpXuANJXq3WTVFcvA== X-Received: by 2002:a05:7300:640b:b0:2b7:2bf3:ce05 with SMTP id 5a478bee46e88-2b7c88e31bbmr5490722eec.28.1770041887384; Mon, 02 Feb 2026 06:18:07 -0800 (PST) MIME-Version: 1.0 References: <5d81fbbb-7609-4445-9bc4-8af211fb7674@dunslane.net> <8e226753-57af-489a-bfbe-caa23dd71286@dunslane.net> In-Reply-To: From: Manni Wood Date: Mon, 2 Feb 2026 08:17:55 -0600 X-Gm-Features: AZwV_QgJxTmvYME1Y36tr0wHREFNu3ibB5mqT4MGa7WWSehbPldw8VkXp9daY8I Message-ID: Subject: Re: Speed up COPY FROM text/CSV parsing using SIMD To: KAZAR Ayoub Cc: Neil Conway , Nazir Bilal Yavuz , Nathan Bossart , Andrew Dunstan , Shinya Kato , PostgreSQL-development Content-Type: multipart/alternative; boundary="000000000000ef79030649d7fddd" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000ef79030649d7fddd Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, Jan 31, 2026 at 10:21=E2=80=AFAM KAZAR Ayoub wrot= e: > Hello, > > On Wed, Jan 21, 2026 at 9:50=E2=80=AFPM Neil Conway wrote: > >> A few suggestions: >> >> * I'm curious if we'll see better performance on large inputs if we flus= h >> to `line_buf` periodically (e.g., at least every few thousand bytes or s= o). >> Otherwise we might see poor data cache behavior if large inputs with no >> control characters get evicted before we've copied them over. See the >> approach taken in escape_json_with_len() in utils/adt/json.c >> >> So i gave this a try, attached is the small patch that has v3 + the > suggestion added, here are the results with different threshold for > line_buf refill: > > Execution time compared to master: > Workload v3 v3.1 (2k) v3.1 (4k) v3.1 (8k) v3.1 (16k) v3.1 (20k) v3.1 (28k= ) > text/none -16.5% -17.4% -14.3% -12.6% -13.6% -10.5% -16.3% > text/esc +5.6% +11.1% +3.1% +7.6% +3.0% +4.9% +4.2% > csv/none -31.0% -29.9% -26.7% -30.1% -27.9% -30.2% -29.6% > csv/quote +0.2% -0.6% -0.4% -1.0% +0.1% +2.5% -1.0% > > L1d cache miss rates: > Workload Master v3 v3.1 (2k) v3.1 (4k) v3.1 (8k) v3.1 (16k) v3.1 (20k) v3= .1 > (28k) > text/none 0.20% 0.23% 0.21% 0.22% 0.21% 0.21% 0.21% 0.22% > text/esc 0.21% 0.22% 0.22% 0.22% 0.22% 0.21% 0.22% 0.22% > csv/none 0.17% 0.22% 0.21% 0.22% 0.21% 0.21% 0.22% 0.22% > csv/quote 0.18% 0.22% 0.19% 0.20% 0.20% 0.19% 0.20% 0.20% > On my laptop I have 32KB L1 cache per core. > Results are super close, it is hard to see in the cache misses numbers bu= t > execution times are saying other things, doing the periodic filling of > line_buf seems good to do. > If Manni can rerun the benchmarks on these too, it would be nice to > confirm this. > > > Regards, > Ayoub > Hello, All! Ayoub, I will try to benchmark v3.1 this week on my standalone x86 and arm PCs. Sadly, other work has been taking priority these last couple weeks, but I will carve out some time. Neil, thanks so much for looking at this patch! -Manni --=20 -- Manni Wood EDB: https://www.enterprisedb.com --000000000000ef79030649d7fddd Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Sat, Jan 31,= 2026 at 10:21=E2=80=AFAM KAZAR Ayoub <ma_kazar@esi.dz> wrote:
Hello,

On Wed, Jan 2= 1, 2026 at 9:50=E2=80=AFPM Neil Conway <neil.conway@gmail.com> wrote:
A few sugg= estions:

* I'm curious if we'll see better performance on la= rge inputs if we flush to `line_buf` periodically (e.g., at least every few= thousand bytes or so). Otherwise we might see poor data cache behavior if = large inputs with no control characters get evicted before we've copied= them over. See the approach taken in=C2=A0escape_json_with_len() in utils/= adt/json.c

So i gave this a try, atta= ched is the small patch that has v3 + the suggestion added, here are the re= sults with different threshold for line_buf refill:

Execution time compared to master:
Workload= v3v3.1 (2k)v3.1 (4k)v3.1 (8k)v3.1 (16k)= v3.1 (20k)v3.1 (28k)
text= /none-16.5%-17.4%-14.3%-12.6%-= 13.6%-10.5%-16.3%
text/esc+5.6%= +11.1%+3.1%+7.6%+3.0%+4.9%+4.2%
csv/none-31.0%-29.9%= -26.7%-30.1%-27.9%-30.2%-29.6%
csv/quote+0.2%-0.6%-0.4%-1.0%<= /td>+0.1%+2.5%-1.0%

L1d cache miss rates:
v3.1 (8k)csv/none<= td>0.19%
Wor= kloadMasterv3v3.1 (2k)v3.1 (4k)v3.1 (16k)v3.1 (20k)v3.1 (28k)
text/none0.20%0.23%0.21= %0.22%0.21%0.21%0.21%0.22%
text/esc0.21%0.22%0.22%0.= 22%0.22%0.21%0.22%0.22%
0.17%0.22%0.21%0.22%= 0.21%0.21%0.22%0.22%
csv/quote<= /td>0.18%0.22%0.19%0.20%0.20%0.20%0.20%

On my=C2=A0laptop I have=C2=A032KB L1 cache per core.
Results a= re super close, it is hard to see in the cache misses=C2=A0numbers but exec= ution times are saying other things, doing the periodic filling of line_buf= seems good to do.
If Manni can rerun the benchmarks on these too, it wo= uld be nice to confirm this.


Regard= s,
Ayoub

Hello, All!
=
Ayoub, I will try to benchmark v3.1 this week on my standalo= ne x86 and arm PCs. Sadly, other work has been taking priority these last c= ouple weeks, but I will carve out some time.

Neil,= thanks so much for looking at this patch!

-Manni<= /div>--
-- Manni Wood EDB: https://www.enterprisedb.com
--000000000000ef79030649d7fddd--