Re: Optimize SnapBuildPurgeOlderTxn: use in-place compaction instead of temporary array - Mailing list pgsql-hackers

From Kirill Reshke
Subject Re: Optimize SnapBuildPurgeOlderTxn: use in-place compaction instead of temporary array
Date
Msg-id CALdSSPigR5SqwqA_KFZOCDH8jw26Mj8V6tOdL5d_AgujjwPe5w@mail.gmail.com
Whole thread Raw
In response to Optimize SnapBuildPurgeOlderTxn: use in-place compaction instead of temporary array  (Xuneng Zhou <xunengzhou@gmail.com>)
List pgsql-hackers
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



pgsql-hackers by date:

Previous
From: Xuneng Zhou
Date:
Subject: Optimize SnapBuildPurgeOlderTxn: use in-place compaction instead of temporary array
Next
From: Tomas Vondra
Date:
Subject: Re: [Proposal] Expose internal MultiXact member count function for efficient monitoring