Re: Strange Bitmapset manipulation in DiscreteKnapsack()
Richard Guo <guofenglinux@gmail.com>
From: Richard Guo <guofenglinux@gmail.com>
To: David Rowley <dgrowleyml@gmail.com>
Cc: PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>
Date: 2024-01-18T02:22:24Z
Lists: pgsql-hackers
On Thu, Jan 18, 2024 at 8:35 AM David Rowley <dgrowleyml@gmail.com> wrote:
> The functions's header comment mentions "The bitmapsets are all
> pre-initialized with an unused high bit so that memory allocation is
> done only once.".
Ah, I neglected to notice this when reviewing the v1 patch. I guess
it's implemented this way due to performance considerations, right?
> I've attached a patch which adds bms_replace_members(). It's basically
> like bms_copy() but attempts to reuse the member from another set. I
> considered if the new function should be called bms_copy_inplace(),
> but left it as bms_replace_members() for now.
Do you think we can use 'memcpy(a, b, BITMAPSET_SIZE(b->nwords))'
directly in the new bms_replace_members() instead of copying the
bitmapwords one by one, like:
- i = 0;
- do
- {
- a->words[i] = b->words[i];
- } while (++i < b->nwords);
-
- a->nwords = b->nwords;
+ memcpy(a, b, BITMAPSET_SIZE(b->nwords));
But I'm not sure if this is an improvement or not.
Thanks
Richard
Commits
-
Fix broken Bitmapset optimization in DiscreteKnapsack()
- 4b310636439d 17.0 landed
-
Require empty Bitmapsets to be represented as NULL.
- 00b41463c216 16.0 cited