Re: Optimize SnapBuildPurgeOlderTxn: use in-place compaction instead of temporary array
Kirill Reshke <reshkekirill@gmail.com>
From: Kirill Reshke <reshkekirill@gmail.com>
To: Xuneng Zhou <xunengzhou@gmail.com>
Cc: pgsql-hackers <pgsql-hackers@lists.postgresql.org>
Date: 2025-10-18T08:59:40Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Introduce logical decoding.
- b89e151054a0 9.4.0 cited
On Sat, 18 Oct 2025 at 12:50, Xuneng Zhou <xunengzhou@gmail.com> wrote: > > Hi Hackers, Hi! > The SnapBuildPurgeOlderTxn function previously used a suboptimal > method to remove old XIDs from the committed.xip array. It allocated a > temporary workspace array, copied the surviving elements into it, and > then copied them back, incurring unnecessary memory allocation and > multiple data copies. > > This patch refactors the logic to use a standard two-pointer, in-place > compaction algorithm. The new approach filters the array in a single > pass with no extra memory allocation, improving both CPU and memory > efficiency. > > No behavioral changes are expected. This resolves a TODO comment > expecting a more efficient algorithm. > Indeed, these changes look correct. I wonder why b89e151054a0 did this place this way, hope we do not miss anything here. Can we construct a microbenchmark here which will show some benefit? -- Best regards, Kirill Reshke