Fix poorly-sized buffers in astreamer compression modules.

astreamer_gzip.c and astreamer_lz4.c left their decompression
output buffers at StringInfo's default allocation, merely 1kB.
This results in a lot of ping-ponging between the decompressor
and the next astreamer filter.  This patch increases these buffer
sizes to 256kB.  In a simple test this had a small but measurable
effect (saving a few percent) on the overall runtime of pg_waldump
for the gzipped-data case; I didn't bother measuring for lz4.

astreamer_zstd.c used ZSTD_DStreamOutSize() to size its
compression output buffer, but the libzstd API says you should use
ZSTD_CStreamOutSize(); ZSTD_DStreamOutSize() is for decompression.
The two functions seem to produce the same value (256kB) here, so
this is just cosmetic, but nonetheless we should play by the rules.

While these issues are old, they don't seem significant enough to
warrant back-patching.

Discussion: https://postgr.es/m/3424809.1774234940@sss.pgh.pa.us
This commit is contained in:
Tom Lane 2026-03-24 12:17:04 -04:00
parent ca1f1ade3f
commit 6e243d81c5
3 changed files with 5 additions and 1 deletions

View file

@ -247,6 +247,8 @@ astreamer_gzip_decompressor_new(astreamer *next)
streamer->base.bbs_next = next;
initStringInfo(&streamer->base.bbs_buffer);
/* Use a buffer size comparable to the other decompressors */
enlargeStringInfo(&streamer->base.bbs_buffer, 256 * 1024 - 1);
/* Initialize internal stream state for decompression */
zs = &streamer->zstream;

View file

@ -288,6 +288,8 @@ astreamer_lz4_decompressor_new(astreamer *next)
streamer->base.bbs_next = next;
initStringInfo(&streamer->base.bbs_buffer);
/* Use a buffer size comparable to the compressor's */
enlargeStringInfo(&streamer->base.bbs_buffer, 256 * 1024 - 1);
/* Initialize internal stream state for decompression */
ctxError = LZ4F_createDecompressionContext(&streamer->dctx, LZ4F_VERSION);

View file

@ -82,7 +82,7 @@ astreamer_zstd_compressor_new(astreamer *next, pg_compress_specification *compre
streamer->base.bbs_next = next;
initStringInfo(&streamer->base.bbs_buffer);
enlargeStringInfo(&streamer->base.bbs_buffer, ZSTD_DStreamOutSize());
enlargeStringInfo(&streamer->base.bbs_buffer, ZSTD_CStreamOutSize());
streamer->cctx = ZSTD_createCCtx();
if (!streamer->cctx)