Improve catcache/syscache performance.
Andres Freund <andres@anarazel.de>
From: Andres Freund <andres@anarazel.de>
To: pgsql-hackers@postgresql.org
Date: 2017-09-14T06:12:07Z
Lists: pgsql-hackers
Attachments
- 0004-Add-inline-murmurhash32-int32-function.patch (text/x-diff)
Hi, There's plenty workloads where SearchSysCache()/SearchCatCache() shows up as a major runtime factor. Primarily in workloads with very fast queries. A fair while ago, before I had my commit bit, I'd posted [1]. Looking at the profiles/benchmarks I was easily able to confirm that it still helps, but that there's also still a lot left on the table. Attached is a patch that tries to improve sys/catcache performance, going further than the patch referenced earlier. This primarily includes four pieces: 1) Avoidance of FunctionCallInfo based function calls, replaced by more efficient functions with a native C argument interface. 2) Only initializing the ScanKey when necessary, i.e. catcache misses, reduces cache unnecessary cpu cache misses. 3) Allowing the compiler to specialize critical SearchCatCache for a specific number of attributes allows to unroll loops and avoid other nkeys dependant initialization. 4) Split of the heap lookup from the hash lookup, reducing stack allocations etc in the common case. There's further potential: - replace open coded hash with simplehash - the list walk right now shows up in profiles. - As oid is the only system column supported, avoid the use of heap_getsysattr(), by adding an explicit branch for ObjectIdAttributeNumber. This shows up in profiles. - move cache initialization out of the search path - 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. This patch gives me roughly 8% speedup in a workload that consists out of a fast query that returns a lot of columns. If I apply a few other performance patches, this patch itself starts to make a bigger difference, of around 11%. Greetings, Andres Freund [1] https://www.postgresql.org/message-id/20130905191323.GC490889@alap2.anarazel.de
Commits
-
Improve sys/catcache performance.
- 141fd1b66ce6 11.0 landed
-
Add pg_noinline macro to c.h.
- a0247e7a11bb 11.0 landed
-
Add inline murmurhash32(uint32) function.
- 791961f59b79 11.0 landed