Re: reducing the footprint of ScanKeyword (was Re: Large writable variables)
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andres Freund <andres@anarazel.de>
Cc: John Naylor <john.naylor@2ndquadrant.com>,
Andrew Dunstan <andrew.dunstan@2ndquadrant.com>,
Joerg Sonnenberger <joerg@bec.de>,
David Rowley <david.rowley@2ndquadrant.com>,
John Naylor <jcnaylor@gmail.com>,
PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2019-01-08T21:54:06Z
Lists: pgsql-hackers
Attachments
- perfect-hash-for-fmgr-oids-1.patch (text/x-diff) patch
Andres Freund <andres@anarazel.de> writes: > On 2019-01-08 13:41:16 -0500, John Naylor wrote: >> Do you mean the fmgr table? > Not the entire fmgr table, but just the builtin oid index, generated by > the following section: > ... > The generated fmgr_builtin_oid_index is pretty sparse, and a more dense > hashtable might e.g. more efficient from a cache perspective. I experimented with this, but TBH I think it's a dead loss. We currently have 2768 built-in functions, so the perfect hash table requires 5537 int16 entries, which is not *that* much less than the 10000 entries that are in fmgr_builtin_oid_index presently. When you consider the extra cycles needed to do the hashing, and the fact that you have to touch (usually) two cache lines not one in the lookup table, it's hard to see how this could net out as a win performance-wise. Also, I fail to understand why fmgr_builtin_oid_index has 10000 entries anyway. We could easily have fmgrtab.c expose the last actually assigned builtin function OID (presently 6121) and make the index array only that big, which just about eliminates the space advantage completely. BTW, I found out while trying this that Joerg's fear of the hash multipliers being too simplistic is valid: the perfect hash generator failed until I changed them. I picked a larger value that should be just as easy to use for shift-and-add purposes. regards, tom lane
Commits
-
Use perfect hashing, instead of binary search, for keyword lookup.
- c64d0cd5ce24 12.0 landed
-
Reduce the size of the fmgr_builtin_oid_index[] array.
- 8ff5f824dca7 12.0 landed
-
Replace the data structure used for keyword lookup.
- afb0d0712f1a 12.0 landed