forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitafb0d07
committed
Replace the data structure used for keyword lookup.
Previously, ScanKeywordLookup was passed an array of string pointers.This had some performance deficiencies: the strings themselves mightbe scattered all over the place depending on the compiler (and somequick checking shows that at least with gcc-on-Linux, they indeedweren't reliably close together). That led to very cache-unfriendlybehavior as the binary search touched strings in many different pages.Also, depending on the platform, the string pointers might need tobe adjusted at program start, so that they couldn't be simple constantdata. And the ScanKeyword struct had been designed with an eye to32-bit machines originally; on 64-bit it requires 16 bytes perkeyword, making it even more cache-unfriendly.Redesign so that the keyword strings themselves are allocatedconsecutively (as part of one big char-string constant), therebyeliminating the touch-lots-of-unrelated-pages syndrome. And getrid of the ScanKeyword array in favor of three separate arrays:uint16 offsets into the keyword array, uint16 token codes, anduint8 keyword categories. That reduces the overhead per keywordto 5 bytes instead of 16 (even less in programs that only needone of the token codes and categories); moreover, the binary searchonly touches the offsets array, further reducing its cache footprint.This also lets us put the token codes somewhere else than thekeyword strings are, which avoids some unpleasant build dependencies.While we're at it, wrap the data used by ScanKeywordLookup intoa struct that can be treated as an opaque type by most callers.That doesn't change things much right now, but it will make itless painful to switch to a hash-based lookup method, as is beingdiscussed in the mailing list thread.Most of the change here is associated with adding a generatorscript that can build the new data structure from the samelist-of-PG_KEYWORD header representation we used before.The PG_KEYWORD lists that plpgsql and ecpg used to embed intheir scanner .c files have to be moved into headers, and theMakefiles have to be taught to invoke the generator script.This work is also necessary if we're to consider hash-based lookup,since the generator script is what would be responsible forconstructing a hash table.Aside from saving a few kilobytes in each program that includesthe keyword table, this seems to speed up raw parsing (flex+bison)by a few percent. So it's worth doing even as it stands, thoughwe think we can gain even more with a follow-on patch to switchto hash-based lookup.John Naylor, with further hacking by meDiscussion:https://postgr.es/m/CAJVSVGXdFVU2sgym89XPL=Lv1zOS5=EHHQ8XWNzFL=mTXkKMLw@mail.gmail.com1 parentc5c7fa2 commitafb0d07
File tree
32 files changed
+843
-439
lines changed- contrib/pg_stat_statements
- src
- backend
- parser
- utils/adt
- common
- fe_utils
- include
- common
- parser
- interfaces/ecpg/preproc
- pl/plpgsql/src
- tools
- msvc
32 files changed
+843
-439
lines changedLines changed: 2 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3075 | 3075 |
| |
3076 | 3076 |
| |
3077 | 3077 |
| |
3078 |
| - | |
3079 |
| - | |
| 3078 | + | |
| 3079 | + | |
3080 | 3080 |
| |
3081 | 3081 |
| |
3082 | 3082 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
41 | 41 |
| |
42 | 42 |
| |
43 | 43 |
| |
44 |
| - | |
| 44 | + | |
45 | 45 |
| |
46 | 46 |
| |
47 | 47 |
| |
|
Lines changed: 33 additions & 18 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
66 | 66 |
| |
67 | 67 |
| |
68 | 68 |
| |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
69 | 84 |
| |
70 | 85 |
| |
71 | 86 |
| |
| |||
504 | 519 |
| |
505 | 520 |
| |
506 | 521 |
| |
507 |
| - | |
| 522 | + | |
508 | 523 |
| |
509 | 524 |
| |
510 | 525 |
| |
511 | 526 |
| |
512 |
| - | |
513 |
| - | |
514 |
| - | |
515 |
| - | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
516 | 530 |
| |
517 |
| - | |
518 |
| - | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
519 | 534 |
| |
520 | 535 |
| |
521 | 536 |
| |
| |||
1021 | 1036 |
| |
1022 | 1037 |
| |
1023 | 1038 |
| |
1024 |
| - | |
| 1039 | + | |
1025 | 1040 |
| |
1026 | 1041 |
| |
1027 | 1042 |
| |
1028 | 1043 |
| |
1029 | 1044 |
| |
1030 |
| - | |
1031 |
| - | |
1032 |
| - | |
1033 |
| - | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
1034 | 1048 |
| |
1035 |
| - | |
1036 |
| - | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
1037 | 1052 |
| |
1038 | 1053 |
| |
1039 | 1054 |
| |
| |||
1142 | 1157 |
| |
1143 | 1158 |
| |
1144 | 1159 |
| |
1145 |
| - | |
1146 |
| - | |
| 1160 | + | |
| 1161 | + | |
1147 | 1162 |
| |
1148 | 1163 |
| |
1149 | 1164 |
| |
| |||
1153 | 1168 |
| |
1154 | 1169 |
| |
1155 | 1170 |
| |
1156 |
| - | |
1157 |
| - | |
| 1171 | + | |
| 1172 | + | |
1158 | 1173 |
| |
1159 | 1174 |
| |
1160 | 1175 |
| |
|
Lines changed: 5 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
417 | 417 |
| |
418 | 418 |
| |
419 | 419 |
| |
420 |
| - | |
| 420 | + | |
421 | 421 |
| |
422 | 422 |
| |
423 | 423 |
| |
424 | 424 |
| |
425 | 425 |
| |
426 |
| - | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
427 | 429 |
| |
428 |
| - | |
| 430 | + | |
429 | 431 |
| |
430 | 432 |
| |
431 | 433 |
| |
|
Lines changed: 2 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
10601 | 10601 |
| |
10602 | 10602 |
| |
10603 | 10603 |
| |
10604 |
| - | |
10605 |
| - | |
10606 |
| - | |
| 10604 | + | |
10607 | 10605 |
| |
10608 |
| - | |
| 10606 | + | |
10609 | 10607 |
| |
10610 | 10608 |
| |
10611 | 10609 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
| 1 | + |
Lines changed: 15 additions & 11 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
41 | 41 |
| |
42 | 42 |
| |
43 | 43 |
| |
44 |
| - | |
| 44 | + | |
45 | 45 |
| |
46 | 46 |
| |
47 | 47 |
| |
48 |
| - | |
| 48 | + | |
49 | 49 |
| |
50 | 50 |
| |
51 | 51 |
| |
| |||
65 | 65 |
| |
66 | 66 |
| |
67 | 67 |
| |
| 68 | + | |
| 69 | + | |
68 | 70 |
| |
69 | 71 |
| |
70 | 72 |
| |
| |||
115 | 117 |
| |
116 | 118 |
| |
117 | 119 |
| |
118 |
| - | |
119 |
| - | |
120 |
| - | |
121 |
| - | |
122 |
| - | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
123 | 123 |
| |
124 |
| - | |
125 |
| - | |
126 |
| - | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
127 | 127 |
| |
128 |
| - | |
| 128 | + | |
| 129 | + | |
129 | 130 |
| |
130 | 131 |
| |
| 132 | + | |
| 133 | + | |
| 134 | + |
Lines changed: 9 additions & 90 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1 | 1 |
| |
2 | 2 |
| |
3 | 3 |
| |
4 |
| - | |
| 4 | + | |
5 | 5 |
| |
6 | 6 |
| |
7 | 7 |
| |
| |||
13 | 13 |
| |
14 | 14 |
| |
15 | 15 |
| |
16 |
| - | |
17 |
| - | |
18 |
| - | |
19 |
| - | |
20 |
| - | |
| 16 | + | |
21 | 17 |
| |
22 |
| - | |
23 |
| - | |
24 |
| - | |
| 18 | + | |
25 | 19 |
| |
26 |
| - | |
27 | 20 |
| |
28 |
| - | |
| 21 | + | |
29 | 22 |
| |
30 |
| - | |
31 |
| - | |
32 |
| - | |
33 |
| - | |
34 |
| - | |
35 |
| - | |
36 |
| - | |
| 23 | + | |
37 | 24 |
| |
38 |
| - | |
| 25 | + | |
39 | 26 |
| |
| 27 | + | |
40 | 28 |
| |
41 |
| - | |
| 29 | + | |
42 | 30 |
| |
43 | 31 |
| |
44 | 32 |
| |
45 |
| - | |
46 |
| - | |
47 |
| - | |
48 |
| - | |
49 |
| - | |
50 |
| - | |
51 |
| - | |
52 |
| - | |
53 |
| - | |
54 |
| - | |
55 |
| - | |
56 |
| - | |
57 |
| - | |
58 |
| - | |
59 |
| - | |
60 |
| - | |
61 |
| - | |
62 |
| - | |
63 |
| - | |
64 |
| - | |
65 |
| - | |
66 |
| - | |
67 |
| - | |
68 |
| - | |
69 |
| - | |
70 |
| - | |
71 |
| - | |
72 |
| - | |
73 |
| - | |
74 |
| - | |
75 |
| - | |
76 |
| - | |
77 |
| - | |
78 |
| - | |
79 |
| - | |
80 |
| - | |
81 |
| - | |
82 |
| - | |
83 |
| - | |
84 |
| - | |
85 |
| - | |
86 |
| - | |
87 |
| - | |
88 |
| - | |
89 |
| - | |
90 |
| - | |
91 |
| - | |
92 |
| - | |
93 |
| - | |
94 |
| - | |
95 |
| - | |
96 |
| - | |
97 |
| - | |
98 |
| - | |
99 |
| - | |
100 |
| - | |
101 |
| - | |
102 |
| - | |
103 |
| - | |
104 |
| - | |
105 |
| - | |
106 |
| - | |
107 |
| - | |
108 |
| - | |
109 |
| - | |
110 |
| - | |
111 |
| - | |
112 |
| - | |
113 |
| - | |
114 |
| - | |
| 33 | + |
0 commit comments
Comments
(0)