Re: reducing the footprint of ScanKeyword (was Re: Large writable variables)
John Naylor <jcnaylor@gmail.com>
From: John Naylor <jcnaylor@gmail.com>
To: Robert Haas <robertmhaas@gmail.com>
Cc: Andres Freund <andres@anarazel.de>,
Andrew Gierth <andrew@tao11.riddles.org.uk>, Tom Lane <tgl@sss.pgh.pa.us>, "pgsql-hackers@postgresql.org" <pgsql-hackers@postgresql.org>
Date: 2018-12-27T16:19:51Z
Lists: pgsql-hackers
Attachments
- v4-0001-WIP-Use-offset-based-keyword-lookup.patch (text/x-patch) patch v4-0001
- v4-0002-Dispatch-keyword-lookup-on-the-first-character.patch (text/x-patch) patch v4-0002
On 12/26/18, John Naylor <jcnaylor@gmail.com> wrote: > On 12/26/18, Robert Haas <robertmhaas@gmail.com> wrote: >> I wonder if we could do something really simple like a lookup based on >> the first character of the scan keyword. It looks to me like there are >> 440 keywords right now, and the most common starting letter is 'c', >> which is the first letter of 51 keywords. So dispatching based on the >> first letter clips at least 3 steps off the binary search. I don't >> know whether that's enough to be worthwhile, but it's probably pretty >> simple to implement. > I agree it'd be fairly simple to do, and might raise the bar for doing > anything more complex. I went ahead and did this for v4, but split out into a separate patch. In addition, I used a heuristic to bypass binary search for the most common keywords. Normally, the middle value is computed mathematically, but I found that in each range of keywords beginning with the same letter, there is often 1 or 2 common keywords that are good first guesses, such as select, from, join, limit, where. I taught the lookup to try those first, and then compute subsequent steps the usual way. Barring additional bikeshedding on 0001, I'll plan on implementing offset-based lookup for the other keyword types and retire the old ScanKeyword. Once that's done, we can benchmark and compare with the optimizations in 0002. -John Naylor
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