Re: bugfix patch for json_array_elements - Mailing list pgsql-hackers

From Andrew Dunstan
Subject Re: bugfix patch for json_array_elements
Date
Msg-id 52EFA21F.60707@dunslane.net
Whole thread Raw
In response to Re: bugfix patch for json_array_elements  (Craig Ringer <craig@2ndquadrant.com>)
Responses Re: bugfix patch for json_array_elements  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On 02/02/2014 08:54 PM, Craig Ringer wrote:
> On 02/03/2014 09:09 AM, Craig Ringer wrote:
>
>> At a guess, we're looking at a case where a new child context is created
>> at every call, so every MemoryContextResetChildren call has to deal with
>> more child contexts.
> That would be "yes". After a short run, I see 32849 lines like:
>
> json_array_elements temporary cxt: 8192 total in 1 blocks; 8160 free (0
> chunks); 32 used
>
> under the context:
>
>    PortalMemory: 8192 total in 1 blocks
>      PortalHeapMemory: 7168 total in 3 blocks
>        ExecutorState: 65600 total in 4 blocks
>          ExprContext: 8192 total in 1 blocks
>            json_array_elements temporary cxt: 8192 total in 1 blocks;
> 8160 free (0 chunks); 32 used
>
>
> The attached patch deletes the context after use, bringing performance
> back into line. It should be backpatched to 9.3.

[...]
> +    MemoryContextDelete(state->tmp_cxt);
> +    state->tmp_cxt = NULL;
> +
>       PG_RETURN_NULL();



Hmm. I guess I was assuming that the tmp_cxt would be cleaned up at the 
end of the function since it's a child of the CurrentMemoryContext. But 
if I got that wrong I'm happy to fix it. I don't see the point in 
setting state->tmp_cxt to NULL since it's about to go out of scope anyway.


cheers

andrew



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: narwhal and PGDLLIMPORT
Next
From: "MauMau"
Date:
Subject: Re: [review] PostgreSQL Service on Windows does not start if data directory given is relative path