Re: Optimize memory allocation code - Mailing list pgsql-hackers

From Merlin Moncure
Subject Re: Optimize memory allocation code
Date
Msg-id CAHyXU0ySj1c07RwcuiMKGJD+yTD+RFZq0tyK+M4ooPT5xf3UpQ@mail.gmail.com
Whole thread Raw
In response to Re: Optimize memory allocation code  (Li Japin <japinli@hotmail.com>)
Responses Re: Optimize memory allocation code  (Tomas Vondra <tomas.vondra@2ndquadrant.com>)
List pgsql-hackers
On Fri, Sep 25, 2020 at 7:32 PM Li Japin <japinli@hotmail.com> wrote:
>
>
>
> > On Sep 26, 2020, at 8:09 AM, Julien Rouhaud <rjuju123@gmail.com> wrote:
> >
> > Hi,
> >
> > On Sat, Sep 26, 2020 at 12:14 AM Li Japin <japinli@hotmail.com> wrote:
> >>
> >> Hi, hackers!
> >>
> >> I find the palloc0() is similar to the palloc(), we can use palloc() inside palloc0()
> >> to allocate space, thereby I think we can reduce  duplication of code.
> >
> > The code is duplicated on purpose.  There's a comment at the beginning
> > that mentions it:
> >
> >  /* duplicates MemoryContextAllocZero to avoid increased overhead */
> >
> > Same for MemoryContextAllocZero() itself.
>
> Thanks! How big is this overhead? Is there any way I can test it?

Profiler.  For example, oprofile. In hot areas of the code (memory
allocation is very hot), profiling is the first step.

merlin



pgsql-hackers by date:

Previous
From: Li Japin
Date:
Subject: Re: Optimize memory allocation code
Next
From: Tom Lane
Date:
Subject: Re: a potential size overflow issue