> On 17 Feb 2023, at 05:01, Andres Freund <andres@anarazel.de> wrote:
> ISTM that we really shouldn't use ALLOCSET_DEFAULT_SIZES for expression
> contexts, as they most commonly see only a few small, or no, allocations.
Looking into this I think you are correct.
> ISTM that we could save a reasonable amount of memory by using a smaller
> initial size.
I experimented with the below trivial patch in CreateExprContext:
- return CreateExprContextInternal(estate, ALLOCSET_DEFAULT_SIZES);
+ return CreateExprContextInternal(estate, ALLOCSET_START_SMALL_SIZES);
Across various (unscientific) benchmarks, including expression heavy TPC-H
queries, I can see consistent reductions in memory use and tiny (within the
margin of error) increases in performance. More importantly, I didn't see a
case of slowdowns with this applied or any adverse effects in terms of memory
use. Whenever the initial size isn't big enough the expr runtime is likely
exceeding the overhead from growing the allocation?
--
Daniel Gustafsson