Re: Rethinking MemoryContext creation

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Rethinking MemoryContext creation
Date: 2017-12-12 19:50:37
Message-ID: CA+Tgmoby7bcUuXfy76+XxcUQNtq0CjRG8M87gqxMF-8MyU7LbQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Dec 12, 2017 at 2:30 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> 379 CurTransactionContext was never used
> 24 CurTransactionContext was used
> 66978 ExprContext was never used
> 17364 ExprContext was used
> 11139 SPI Exec was never used
> 2421 SPI Exec was used
> 38386 ginPlaceToPage temporary context was never used
> 3348 ginPlaceToPage temporary context was used

It strikes me that a way to optimize these cases even more would be to
postpone creating the context until it's actually needed. That might
not always be a reasonable plan -- in particular, it occurs to me to
think that CurTransactionContext is probably so widely used that
changing anything about how it works would probably be really painful
-- but it might be possible in some cases.

Another idea I have is that perhaps we could arrange to reuse contexts
instead of destroying them and recreating them. For example, when
asked to delete a context, we could instead push it on a linked list
of old contexts, or only if the list isn't too long already, and when
asked to create one, we could pop from the list. Or we could keep
around an array of, say, 1024 contexts that are never freed and only
allocated dynamically when we run out.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2017-12-12 20:02:08 Re: Rethinking MemoryContext creation
Previous Message Tom Lane 2017-12-12 19:30:58 Re: Rethinking MemoryContext creation