This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Annotate malloc conditions with glibc_likely.
- From: Rich Felker <dalias at aerifal dot cx>
- To: Will Newton <will dot newton at linaro dot org>
- Cc: OndÅej BÃlka <neleai at seznam dot cz>, libc-alpha <libc-alpha at sourceware dot org>
- Date: Tue, 10 Dec 2013 22:22:51 -0500
- Subject: Re: [PATCH] Annotate malloc conditions with glibc_likely.
- Authentication-results: sourceware.org; auth=none
- References: <20131209204454 dot GA6225 at domone dot podge> <CANu=DmjE_RR-kWwOLw92HNr9OmKTAswnsqi2hgCTWi7QigY2xg at mail dot gmail dot com>
On Tue, Dec 10, 2013 at 09:54:31AM +0000, Will Newton wrote:
> On 9 December 2013 20:44, OndÅej BÃlka <neleai@seznam.cz> wrote:
> > Hi,
> >
> > Another little optimization in malloc is annotate that fastbins are
> > likely case. These should be fast path and given that other path
> > slower it should pay off.
>
> In general I am not in favour of adding these types of annotations
> unless we can show they improve performance as they make code harder
> to read. They are also something of a blunt instrument - does "likely"
> mean will happen with 75% likelihood? 90%? 99%? I guess the results
> will vary with compiler and architecture as to whether or not the
> annotation helps or not.
"Likely" means "this is the code path where performance matters". If
you have to choose between adding 5ns to a codepath that normally
takes 30ns or to a codepath that normally takes 1000ns, you always
want to add it to the latter, no matter what the actual probabilities
are, unless the 30ns code path is a stupid error codepath that should
never happen in correct code.
Rich