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 1vW8YM-00Dtui-2s for pgsql-hackers@arkaria.postgresql.org; Thu, 18 Dec 2025 07:36:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vW8YL-000nM3-2h for pgsql-hackers@arkaria.postgresql.org; Thu, 18 Dec 2025 07:36:02 +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 1vW8YL-000nLv-1c for pgsql-hackers@lists.postgresql.org; Thu, 18 Dec 2025 07:36:02 +0000 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vW8YJ-001N7H-1v for pgsql-hackers@postgresql.org; Thu, 18 Dec 2025 07:36:01 +0000 Received: by mail-pg1-x52f.google.com with SMTP id 41be03b00d2f7-bdb6f9561f9so348709a12.3 for ; Wed, 17 Dec 2025 23:35:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766043356; x=1766648156; 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=5xpMr2lsRe5x1PzEggHVZWN8/SusvBFwqhkm+5qKkOc=; b=JxzGb08rf2S43Z0VppUhMBWK4XImzCuSYGg6kaiD1zXXV5ezMhkRfYgnJpsD6ANSC9 IZUrUPiWl49UPeoHnDlJ+/T/Fo6HDBTpP5Q7BlRi44CTnxQUms9TDbmXuhAVyxVLSZas ZcKWutWwI6RECzncU1/6XffVgdcSi10XgEVwSnxFgKgcqlnn5/QkuKEXvpxwJw3KJc+B qChaPjzbNiBUuRpVre2ZSBs00Pra+O2++7CZqGapi21Xr8vKrthLTR+uox9unLV3vjNE UU6mxVPs9rM2WH7pobhftz/Hv7FLKBm+p4aR76WaMJOR34AZM2bqebhGI3D5G+8sYWwS amlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766043356; x=1766648156; 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=5xpMr2lsRe5x1PzEggHVZWN8/SusvBFwqhkm+5qKkOc=; b=EuL4pyfreUqjxqUorAtnf6gdvg5aC6foUTMYFJWvorcLpYVkWtRTGSJj8yryYeIG4g a2xFmfBpbAKzHWBxhHgExMbdcVFlnwT6zZu/Ajzpw/2HoATLkKyrf8zw4cCsfw8jIn84 KZYRBuqPF4Ftg+4S15Ka5NPs0Uh84HXxHJjePLlus++U9Xk31kk2TURUyOF+hcOIktlj Gd56PuXQ8x+m3q/khcoNOAHzn4mP0+LWcqbyp9X/QlifBtrkkXs2gKl2GGeytsf0E7h3 6x7QmjNg9UnCtlQmxXAnX/PbqS+S3GLtfEfVzIFMglKh/KLtkGMC0eKHuPdUE5sZkrya Dg6w== X-Forwarded-Encrypted: i=1; AJvYcCVpuJLtX39aTdujdmjrHXoSdXWHABhJwTo8tZjGnenpLJEFzbjdjyRH02uIfeFgW12g78zmOYBEcDbV0iiS@postgresql.org X-Gm-Message-State: AOJu0YwBzKXCNeaEZypMDKbe9FrWm02rxu38yaPPeudfsxPH7lIMDmN3 5oDueRNWBlRTK46dy4aJBsNAXeV31iEimP0EmNUXAWJeqYCeq0pVESDD70mbRBq3d0Hqi4IXKBi l+CUh1zRZ5bxOO+OEcQs2GMl4X9iqKKk= X-Gm-Gg: AY/fxX7Z5VTBBPNBZ3lb92fNSDGeOXg/rk1Xyy85fHE5xrQtsP9LLvo9K4Qc1cFkEe7 D9v/SkNrn9pvMAYeqr/A8LHWQQtzGppP/1YcAxJ50MJaPTQmrTcZ5HVS1yrNefuQgJrDooYUXLP B3t90joeOrziujwd07HPeXYI2NnKU3omVxGKBAsvpNWUb849+AlI/kczLOPTwnmKvMNcTO1qkcR v0EYrBfUMXqiwmYu+rkVBQYKSB6/3+P2mMOenLYFuQ0NHlN60rKAIsE4VnX69Hpj2SQ3k/3zUt7 GMFsVvA= X-Google-Smtp-Source: AGHT+IFlfFOvgl/g8M4JdPcPdNhrO6SESEXnqmR4t//2OYvuSXLPZqofy5RnkkpfZqCdhVn/HhR0sZ+v5NbPG5SszNA= X-Received: by 2002:a05:7301:18ad:b0:2b0:580b:856c with SMTP id 5a478bee46e88-2b0580b8933mr44029eec.28.1766043356024; Wed, 17 Dec 2025 23:35:56 -0800 (PST) MIME-Version: 1.0 References: <8e226753-57af-489a-bfbe-caa23dd71286@dunslane.net> In-Reply-To: From: Nazir Bilal Yavuz Date: Thu, 18 Dec 2025 10:35:44 +0300 X-Gm-Features: AQt7F2olqLfUfV6P_cdgbt7GpKp25bSWPvC8zy84KbdzDbJ9ukuS5npBYlZlVrI Message-ID: Subject: Re: Speed up COPY FROM text/CSV parsing using SIMD To: Manni Wood Cc: Mark Wong , KAZAR Ayoub , 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, 13 Dec 2025 at 02:09, Manni Wood wrot= e: > > Hello, Everyone! > > I have attached two files. 1) the shell script that Mark and I have been = using to get our test results, and 2) a screenshot of a spreadsheet of my l= atest test results. (Please let me know if there's a different format than = a screenshot that I could share my spreadsheet in.) > > I took greater care this time to compile all three variants of Postgres (= master at bfb335df, master at bfb335df with v4.2 patches installed, master = at bfb335df with v3 patches installed) with the same gcc optimization flags= that would be used to build Postgres packages. To the best of my knowledge= , the two gcc flags of greatest interest would be -g and -O2. I built all t= hree variants of Postgres using meson like so: > > BRANCH=3D$(git branch --show-current) > meson setup build --prefix=3D/home/mwood/compiled-pg-instances/${BRANCH} = --buildtype=3Ddebugoptimized > > It occurred to me that in addition to end users only caring about 1) wall= clock time (is the speedup noticeable in "real time" or just technically f= aster / uses less CPU?) and 2) Postgres binaries compiled with the same opt= imization level one would get when installing Postgres from packages like .= deb or .rpm; in other words, will the user see speedups without having do m= anually compile postgres. > > My interesting finding, on my laptop (ThinkPad P14s Gen 1 running Ubuntu = 24.04.3), is different from Mark Wong's. On my laptop, using three Postgres= installations all compiled with the -O2 optimization flag, I see speedups = with the v4.2 patch except for a 2% slowdown with CSV with 1/3rd quotes (a = 2% slowdown). But with Nazir's proposed v3 patch, I see improvements across= the board. So even for a text file with 1/3rd escape characters, and even = with a CSV file with 1/3rd quotes, I see speedups of 11% and 26% respective= ly. > > The format of these test files originally comes from Ayoub Kazar's test s= cripts; all Mark and I have done in playing with them is make them much lar= ger: 5,000,000 rows, based on the assumption that longer tests are better t= ests. > > I find my results interesting enough that I'd be curious to know if anybo= dy else can reproduce them. It is very interesting that Mark's results are = noticeably different from mine. Thank you for sharing the benchmark script! I ran the benchmarks using your script with --buildtype=3Ddebugoptimized. My results are below: master: 85ddcc2f4c text, no special: 102294 text, 1/3 special: 108946 csv, no special: 121831 csv, 1/3 special: 140063 v3 text, no special: 88890 (13.1% speedup) text, 1/3 special: 110463 (1.4% regression) csv, no special: 89781 (26.3% speedup) csv, 1/3 special: 147094 (5.0% regression) v4.2 text, no special: 87785 (14.2% speedup) text, 1/3 special: 127008 (16.6% regression) csv, no special: 88093 (27.7% speedup) csv, 1/3 special: 164487 (17.4% regression) One thing I noticed is that your benchmark timings appear to have some variance. In my runs, I did not observe differences greater than one second between runs. It is possible that this variance is affecting your results. Before running the benchmarks, I use the these commands [1] to improve result stability; they might be helpful if you are not already using something similar: I did this benchmark on my local and my specs are Intel i5 13600k, 32GB Memory and SATA SSD. [1] sudo cpupower frequency-set --governor=3Dperformance sudo cpupower idle-set -D 0 # disable idle echo "1" | sudo tee /sys/devices/system/cpu/intel_pstate/no_turbo (intel on= ly) --=20 Regards, Nazir Bilal Yavuz Microsoft