Re: Compression of bigger WAL records

From: Anthonin Bonnefoy <anthonin(dot)bonnefoy(at)datadoghq(dot)com>
To: surya poondla <suryapoondla4(at)gmail(dot)com>
Cc: "Andrey M(dot) Borodin" <x4mmm(at)yandex-team(dot)ru>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>
Subject: Re: Compression of bigger WAL records
Date: 2026-08-18 13:48:35
Message-ID: CAO6_Xqofo2PYmLuSXBXj7UJFLzE7xbHQLVWKYW0M4MSwB+LA1w@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Andrey,

I've captured some perf of a backend doing
CHECKPOINT;
SELECT count(*) FROM (SELECT * FROM pgbench_accounts FOR UPDATE);
in a loop to check the difference with and without reusing zstd cctx
for 0001. There's definitely a visible improvement with less time
spent in ZSTD_compress_using_Dict.

+ * Compression context reused across all block images compressed by this
+ * backend. zstd keeps its match tables and window in here, roughly 1.3MB at
+ * the default level, and allocates them on first use. Creating a context per
+ * call would repeat that allocation for every full-page image.

I'm a bit surprised by the 1.3MB estimation, how did you find this
amount? If I check with ZSTD_sizeof_CCtx just after the context is
created, I have:
(gdb) p ZSTD_sizeof_CCtx(zstd_cctx)
$1 = 5288

After being used once, it seems to stay stable with:
(gdb) p ZSTD_sizeof_CCtx(zstd_cctx)
$5 = 154261
So it looks closer to 152KB.

+ if (zstd_cctx == NULL)
+ zstd_cctx = ZSTD_createCCtx();

Would it be worth it to register ZSTD_freeCCtx using on_proc_exit? I
imagine this will be tagged as leaked memory since it's never freed.

Regards,
Anthonin Bonnefoy

Attachment Content-Type Size
zstd_compress_reused.svg image/svg+xml 256.8 KB
zstd_compress.svg image/svg+xml 201.2 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2026-08-18 14:35:01 Re: Allow a prosupport function to be attached to an aggregate
Previous Message Shinya Kato 2026-08-18 13:44:00 Re: pgbench: \gset and \aset should store SQL NULL as the null value