model-writtenrun 3679 - may be wrong, links go to the source messages. Commit-by-commit LLM analysis is in the Commits dialog.
- David Rowley found that DiscreteKnapsack() could no longer preserve bitmap storage by deleting all members, because empty Bitmapsets now become NULL, and proposed an explicit free-and-copy cleanup without backpatching #1; Richard Guo endorsed it and checked other callers for the same pattern #2.
- After examining the deliberate preallocation strategy and measuring substantial extra allocations, David replaced the cleanup with bms_replace_members(), which copies members while reusing destination storage where possible, and reconsidered whether PostgreSQL 16 needed a backpatch #3.
- Andy Fan raised a related detoasting use case that needed to clear bitmap flags without freeing their storage, reporting a performance penalty from repeated allocation #4.
- Richard suggested using memcpy in the new helper #5, but David retained the word-copy loop for consistency with other Bitmapset operations and its expected efficiency for small sets #6.
- David explained that retaining an allocated empty Bitmapset would violate representation invariants and suggested a fixed-size bitset for Andy's use case #7; Andy outlined such an API and suggested it might eventually serve DiscreteKnapsack() too #8.
- Andy questioned the unused high bit used to initialize each knapsack set #9, and David explained that it reserves enough words to prevent later growth allocations #10.
- David committed the second patch unchanged apart from whitespace as 4b31063643 and announced the push #11; the commit deferred backpatching because there had been no complaints.
- Andy accepted the preallocation explanation and left a general fixed-size bitset as a possible future improvement #12; the knapsack fix had landed, while that broader idea remained unimplemented in this thread.