Re: Should CreateExprContext() be using ALLOCSET_DEFAULT_SIZES? - Mailing list pgsql-hackers

From Daniel Gustafsson
Subject Re: Should CreateExprContext() be using ALLOCSET_DEFAULT_SIZES?
Date
Msg-id 11EE0126-9D2B-4AB7-AA98-2AF55F3551E9@yesql.se
Whole thread Raw
In response to Should CreateExprContext() be using ALLOCSET_DEFAULT_SIZES?  (Andres Freund <andres@anarazel.de>)
List pgsql-hackers
> 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




pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: Fix typos and inconsistencies for v16
Next
From: Robert Sjöblom
Date:
Subject: [DOC] Update ALTER SUBSCRIPTION documentation