1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-04 20:11:56 +03:00

Improve compiler code layout in elog/ereport ERROR calls

Here we use a bit of preprocessor trickery to coax supporting compilers
into laying out their generated code so that the code that's in the same
branch as elog(ERROR)/ereport(ERROR) calls is moved away from the hot
path.  Effectively, this reduces the size of the hot code meaning that it
can sit on fewer cache lines.

Performance improvements of between 10-15% have been seen on highly CPU
bound workloads using pgbench's TPC-b benchmark.

What's achieved here is very similar to putting the error condition inside
an unlikely() macro. For example;

if (unlikely(x < 0))
    elog(ERROR, "invalid x value");

now there's no need to make use of unlikely() here as the common macro
used by elog and ereport will now see that elevel is >= ERROR and make use
of a pg_attribute_cold marked version of errstart().

When elevel < ERROR or if it cannot be determined to be constant, the
original behavior is maintained.

Author: David Rowley
Reviewed-by: Andres Freund, Peter Eisentraut
Discussion: https://postgr.es/m/CAApHDvrVpasrEzLL2er7p9iwZFZ%3DJj6WisePcFeunwfrV0js_A%40mail.gmail.com
This commit is contained in:
David Rowley
2020-11-24 12:04:42 +13:00
parent 697e1d02f5
commit 913ec71d68
2 changed files with 26 additions and 1 deletions

View File

@@ -219,6 +219,19 @@ err_gettext(const char *str)
#endif
}
/*
* errstart_cold
* A simple wrapper around errstart, but hinted to be "cold". Supporting
* compilers are more likely to move code for branches containing this
* function into an area away from the calling function's code. This can
* result in more commonly executed code being more compact and fitting
* on fewer cache lines.
*/
pg_attribute_cold bool
errstart_cold(int elevel, const char *domain)
{
return errstart(elevel, domain);
}
/*
* errstart --- begin an error-reporting cycle