[COMMITTERS] pgsql: Improve sys/catcache performance.

Поиск
Список
Период
Сортировка
От Andres Freund
Тема [COMMITTERS] pgsql: Improve sys/catcache performance.
Дата
Msg-id E1e37Vv-0004M1-HX@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Improve sys/catcache performance.

The following are the individual improvements:
1) Avoidance of FunctionCallInfo based function calls, replaced by  more efficient functions with a native C argument
interface.
2) Don't extract columns from a cache entry's tuple whenever matching  entries - instead store them as a Datum array.
Thisalso allows to  get rid of having to build dummy tuples for negative & list  entries, and of a hack for dealing
withcstring vs. text weirdness. 
3) Reorder members of catcache.h struct, so imortant entries are more  likely to be on one cacheline.
4) Allowing the compiler to specialize critical SearchCatCache for a  specific number of attributes allows to unroll
loopsand avoid  other nkeys dependant initialization. 
5) Only initializing the ScanKey when necessary, i.e. catcache misses,  greatly reduces cache unnecessary cpu cache
misses.
6) Split of the cache-miss case from the hash lookup, reducing stack  allocations etc in the common case.
7) CatCTup and their corresponding heaptuple are allocated in one  piece.

This results in making cache lookups themselves roughly three times as
fast - full-system benchmarks obviously improve less than that.

I've also evaluated further techniques:
- replace open coded hash with simplehash - the list walk right now shows up in profiles. Unfortunately it's not easy
todo so safely as an entry's memory location can change at various times, which doesn't work well with the refcounting
andcache invalidation. 
- Cacheline-aligning CatCTup entries - helps some with performance, but the win isn't big and the code for it is ugly,
becausethe tuples have to be freed as well. 
- add more proper functions, rather than macros for SearchSysCacheCopyN etc., but right now they don't show up in
profiles.

The reason the macro wrapper for syscache.c/h have to be changed,
rather than just catcache, is that doing otherwise would require
exposing the SysCache array to the outside.  That might be a good idea
anyway, but it's for another day.

Author: Andres Freund
Reviewed-By: Robert Haas
Discussion: https://postgr.es/m/20170914061207.zxotvyopetm7lrrp@alap3.anarazel.de

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/141fd1b66ce6e3d10518d66d4008bd368f1505fd

Modified Files
--------------
src/backend/utils/cache/catcache.c | 692 +++++++++++++++++++++++++------------
src/backend/utils/cache/syscache.c |  49 ++-
src/include/utils/catcache.h       | 122 ++++---
src/include/utils/syscache.h       |  23 +-
src/tools/pgindent/typedefs.list   |   2 +
5 files changed, 608 insertions(+), 280 deletions(-)


--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers

В списке pgsql-committers по дате отправления:

Предыдущее
От: Andres Freund
Дата:
Сообщение: [COMMITTERS] pgsql: Force "restrict" not to be used when compiling with xlc.
Следующее
От: Tom Lane
Дата:
Сообщение: Re: [COMMITTERS] pgsql: Add pg_noinline macro to c.h.