Here's a v3 incorporating Andres' idea of trying to avoid a separate
palloc for the list cell array. In a 64-bit machine we can have up
to five ListCells in the initial allocation without actually increasing
space consumption at all compared to the old code. So only when a List
grows larger than that do we need more than one palloc.
I'm still having considerable difficulty convincing myself that this
is enough of a win to justify the bug hazards we'll introduce, though.
On test cases like "pg_bench -S" it seems to be pretty much within the
noise level of being the same speed as HEAD. I did see a nice improvement
in the test case described in
https://www.postgresql.org/message-id/6970.1545327857@sss.pgh.pa.us
but considering that that's still mostly a tight loop in
match_eclasses_to_foreign_key_col, it doesn't seem very interesting
as an overall figure of merit.
I wonder what test cases Andres has been looking at that convince
him that we need a reimplementation of Lists.
regards, tom lane