pg_basebackup: removed an unnecessary use of memset in FindStreamingStart

From: yangyz <1197620467(at)qq(dot)com>
To: pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: pg_basebackup: removed an unnecessary use of memset in FindStreamingStart
Date: 2026-02-25 06:31:40
Message-ID: tencent_0794CCE61CBCBB3F22728F132CF506B96D05@qq.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Hackers,

When I read the FindStreamingStart function in pg_receivewal.c, I discovered an unnecessary use of memset.So I removed it, optimizing the performance without affecting its functionality.

The following is the detailed analysis of the reasons:
1.LZ4F_decompress will fully overwrite the output buffer:
When out_size is passed as an input parameter, it denotes the size of the output buffer (outbuf). The decompression operation writes the decompressed data to outbuf. Upon function return, out_size is updated to reflect the actual number of bytes written. Notably, even in cases of partial decompression, data is written starting from the initial position of outbuf.
2.Performance Overhead
In each iteration, the entire buffer of size LZ4_CHUNK_SZ (potentially several megabytes) is zero-initialized. Since these memory blocks are immediately overwritten by decompressed data, this zeroing operation constitutes an unnecessary consumption of CPU resources.

Regards,

Yang Yuanzhuo

Attachment Content-Type Size
v1-0001-Removed-an-unnecessary-use-of-memset-in-FindStrea.patch application/octet-stream 1.5 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Zhijie Hou (Fujitsu) 2026-02-25 06:33:10 RE: Skipping schema changes in publication
Previous Message Maxim Orlov 2026-02-25 06:15:25 Re: POC: make mxidoff 64 bits