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 1voMFB-001zbS-0a for pgsql-hackers@arkaria.postgresql.org; Fri, 06 Feb 2026 13:51: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 1voMF9-003zIL-38 for pgsql-hackers@arkaria.postgresql.org; Fri, 06 Feb 2026 13:51:31 +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 1voMF9-003zIC-1k for pgsql-hackers@lists.postgresql.org; Fri, 06 Feb 2026 13:51:31 +0000 Received: from mail-dl1-x122f.google.com ([2607:f8b0:4864:20::122f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1voMF7-00000000qdQ-1lwL for pgsql-hackers@postgresql.org; Fri, 06 Feb 2026 13:51:30 +0000 Received: by mail-dl1-x122f.google.com with SMTP id a92af1059eb24-1233c155a42so2802390c88.1 for ; Fri, 06 Feb 2026 05:51:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1770385888; cv=none; d=google.com; s=arc-20240605; b=Mqy19VhQ8Zz86YKapC71TYE4guY4llkNDFFhKIm0ypE0RnCVD8/Rs+YTKoHjXbpOs2 Lc00MV+sLdHdzm+yeDiNUM0VQpsB2R9tCOH9vFmcIr2K+6+Z60o+mb4csCXxKjH7hqGt qyPuihG+/pNMzs/O5QzszzdhcBOQZ4DosVz07urt4BF3E9oMkxlN+10cAuDBdb0Og+2O yEQGe/m0267NivCIe7+MGY1+ILku0LAQv+7J2OFwsOrWj+EcZNfDL6dSR6osOcbSVjzN PiUwx+DUAiV1KMEn3FzwZbMbM/7zgBOWU80qvYqFwENq8XZmUAynas2rneWTYObrxU/g KD7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=6KwnlWymFtq7FWt/hHBpvbEZ7Nbk27pNmSRqn9OmBSY=; fh=MSVaS0oAlDeuX5Lf118uGuYcmR/YvDSimaxnR9sd1MQ=; b=ihhq4gpH5UKVcMjtyz6oQY6S4NFV3iPALIr5VpeEw9vvuOXSC/tB1WB50MPgJPWzee mzN0LDoMbKgdMgp3nzdLW0nhEWLQflU10LptDJTgzRAVHiWRPvpsVEZz0Qecf5VJ62r/ iwermubMiqLUOk+fJ5uMqbh6s4UFVitsL85Z3+xilCfa8oCABROonM3xDj/GswJ1Goor Au5LH+Ko2sX9Vt4Osn1Mvp1EQ4N2KuYEipMfohTHjADqHXy8d4BVD1qCK5QMwkTy6PqT DJ1vZ+C6q98e9/c+1fnQRAJJbDHitY0BkMiC1CKv79Z/Wvpk4iPL+ATbfu5gu88POJoH cZnA==; 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=1770385888; x=1770990688; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=6KwnlWymFtq7FWt/hHBpvbEZ7Nbk27pNmSRqn9OmBSY=; b=Xva7XM7a5phLXPeLXOQDfubNUKrcTO/Ac5GsHvOfkOrWQEHO+RRFgqPpCbYx14jEaE ATV+OO2xxw7R/CB6g7Z/RG8Cx+y5aXodA+ctRTclfyyBOYlNJmWQJDMUsM6ZdF/Xr91K k+5HNHKSHOAux9O/q6NBkVBL+Y3y4EKXL7WLbGiTPAeeeSpjADj7znPqaq4tRTnUoLyo RVP5sr3Bfs+FVrGDHsVpixaKnfiPB98kqWYnTDhDPpu78UUKcZTu3f7iVflyhlggVglg p6JH7EGhSyPis04V44tfD7e3lgm0Jn1/zJ7BUTH/CUUV4lpEJbBYTISQ7VY+YwKXYYld EtTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770385888; x=1770990688; h=content-transfer-encoding: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=6KwnlWymFtq7FWt/hHBpvbEZ7Nbk27pNmSRqn9OmBSY=; b=Nk8sUe+R4loR4fYyJuEFUAvy1WudQ8gpqbJsG+iJ0+89/HuBBSK3yxvHyTlc+QqU1U 94t1kZ3gtABxMtKgR7IcHd2toMxyGgj5JawFAWlnJoaEMO5wQiMXoDrTMsJrQUWoQXNY q/rJo3MSPghMWLp6utqN423PWLQW3PfK4W3oy1DBDSk/4/95+wkSv83s+916jbWz63Hm 5DqX+zB9kZCzFbQ+LI8Lu8ewkmtw09DQmCQdKypIazDyuXOMHLAbOsOLy2kRA+WYFZwM yIgDHGXS2lWjrTgK3BlLKJC2OEw2gPbeaJQxbTSJ2Mzsi1x0U1mUvlR1EbKrgHIlKKVS 39fg== X-Forwarded-Encrypted: i=1; AJvYcCUOYtHzf3LsRuEVgMkXrbdGJimL2dSGadxV1KZGRVKqYMikYsV8cMOEZLLcDK+UoarrBgqzUh/Tbcdt3r4Y@postgresql.org X-Gm-Message-State: AOJu0YxhJwoRuxeHbD/3QA76gjPlT3ipVrHMffxFVeUh3pOrqxKdMajS PGJWLzqTQuTSlWIgyzIdKcXCtqP/sYY+9r35lpkVrcRzIc7ChXAUvGC5vZBN6sHuafI5KdQ5Lad kB7f63YVu/PoxgnsCe+peUg5fkLj2jxY= X-Gm-Gg: AZuq6aKgOSoFbLr51kMZDAxUROE6GyzTPBh7+j5qHf+AUDatkl0o2j2IOx7xH5aF4Qu aJGOXrbewKgzSObtVsWdIBMTWD4yX0yv8zFRrcskg0zkDYS2FNx5Opu3ZarGW1Y86UT4jeGTs31 C+zFEujmUSi/PbZ1WBkpUA49fDaI4GSpi7mE6ZO+hMUrzspP1xa5Dgwf+ZTSgtv+ZwNqun2V3YD yulgppxK0UargDoZVvRNrDzcS0ydsc0uuiRo2kfFP2Nel8ghvOENzLcq0CiUOR+EMJJ5A== X-Received: by 2002:a05:7022:b9b:b0:11b:9386:8271 with SMTP id a92af1059eb24-1270407446dmr1452100c88.46.1770385888304; Fri, 06 Feb 2026 05:51:28 -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: Nazir Bilal Yavuz Date: Fri, 6 Feb 2026 16:51:17 +0300 X-Gm-Features: AZwV_Qj6uOoHaJWhutZxuzpmQP55eiravMqLnI6wkZ04MaQ5Efg6Hy1lp8qqiNU Message-ID: Subject: Re: Speed up COPY FROM text/CSV parsing using SIMD To: KAZAR Ayoub Cc: Neil Conway , Manni Wood , Nathan Bossart , Andrew Dunstan , Shinya Kato , PostgreSQL-development Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Sat, 31 Jan 2026 at 19:21, KAZAR Ayoub wrote: > > On Wed, Jan 21, 2026 at 9:50=E2=80=AFPM Neil Conway wrote: >> >> * 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 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 appro= ach 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 sugge= stion added, here are the results with different threshold for line_buf ref= ill: > > Execution time compared to master: > Workloadv3v3.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: > WorkloadMasterv3v3.1 (2k)v3.1 (4k)v3.1 (8k)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% > csv/none0.17%0.22%0.21%0.22%0.21%0.21%0.22%0.22% > csv/quote0.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 li= ne_buf seems good to do. > If Manni can rerun the benchmarks on these too, it would be nice to confi= rm this. I looked at this change and had a couple of points. We already have REFILL_LINEBUF at the start of the for loop in the CopyReadLineText() function (let=E2=80=99s call this refill #1). This refil= ls when the input_buf_ptr >=3D copy_buf_len check is true. On my end, copy_buf_len stays at 8191 until the end of the input, and then it becomes the remaining amount. So when I set LINE_BUF_FLUSH_AFTER to 8192, the REFILL_LINEBUF you added shouldn=E2=80=99t be called; instead, refill #1 should be triggered. I verified this manually by adding some logging, and the results seem to confirm this behavior. Based on that, there shouldn=E2=80=99t be a performance difference when LINE_BUF_FLUSH_AFTER >=3D 8k. Could you please take a look and confirm whether you see the same behavior? Also, I noticed that json.c uses ESCAPE_JSON_FLUSH_AFTER set to 512, so it might be worth trying smaller values here as well. --=20 Regards, Nazir Bilal Yavuz Microsoft