forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit6b423ec
committed
Improve performance of pg_strtointNN functions
Experiments have shown that modern versions of both gcc and clang areunable to fully optimize the multiplication by 10 that we're doing in thepg_strtointNN functions. Both compilers seem to be making use of "imul",which is not the most efficient way to multiply by 10. This seems to bedue to the overflow checking that we're doing. Without the overflowchecks, both those compilers switch to a more efficient method ofmultiplying by 10. In absence of overflow concern, integer multiplicationby 10 can be done by bit-shifting left 3 places to multiply by 8 and thenadding the original value twice.To allow compilers this flexibility, here we adjust the code so that weaccumulate the number as an unsigned version of the type and remove theuse of pg_mul_sNN_overflow() and pg_sub_sNN_overflow(). The overflowchecking can be done simply by checking if the accumulated value has gonebeyond a 10th of the maximum *signed* value for the given type. If it hasthen the accumulation of the next digit will cause an overflow. Afterthis is done, we do a final overflow check before converting the unsignedversion of the number back to its signed counterpart.Testing has shown about an 8% speedup of a COPY into a table containing 2INT columns.Author: David Rowley, Dean RasheedDiscussion:https://postgr.es/m/CAApHDvrL6_+wKgPqRHr7gH_6xy3hXM6a3QCsZ5ForurjDFfenA@mail.gmail.comDiscussion:https://postgr.es/m/CAApHDvrdYByjfj-=WbmVNFgmVZg88-dE7heukw8p55aJ+W=qxQ@mail.gmail.com1 parent29452de commit6b423ec
1 file changed
+42
-44
lines changedLines changed: 42 additions & 44 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
91 | 91 |
| |
92 | 92 |
| |
93 | 93 |
| |
94 |
| - | |
| 94 | + | |
95 | 95 |
| |
96 |
| - | |
| 96 | + | |
97 | 97 |
| |
98 | 98 |
| |
99 | 99 |
| |
100 | 100 |
| |
101 | 101 |
| |
102 |
| - | |
| 102 | + | |
103 | 103 |
| |
104 | 104 |
| |
105 | 105 |
| |
| |||
122 | 122 |
| |
123 | 123 |
| |
124 | 124 |
| |
125 |
| - | |
126 |
| - | |
127 |
| - | |
128 |
| - | |
| 125 | + | |
129 | 126 |
| |
| 127 | + | |
| 128 | + | |
130 | 129 |
| |
131 | 130 |
| |
132 | 131 |
| |
| |||
136 | 135 |
| |
137 | 136 |
| |
138 | 137 |
| |
139 |
| - | |
| 138 | + | |
140 | 139 |
| |
141 |
| - | |
142 |
| - | |
| 140 | + | |
| 141 | + | |
143 | 142 |
| |
144 |
| - | |
| 143 | + | |
145 | 144 |
| |
146 | 145 |
| |
147 |
| - | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
148 | 150 |
| |
149 | 151 |
| |
150 | 152 |
| |
| |||
167 | 169 |
| |
168 | 170 |
| |
169 | 171 |
| |
170 |
| - | |
| 172 | + | |
171 | 173 |
| |
172 |
| - | |
| 174 | + | |
173 | 175 |
| |
174 | 176 |
| |
175 | 177 |
| |
176 | 178 |
| |
177 | 179 |
| |
178 |
| - | |
| 180 | + | |
179 | 181 |
| |
180 | 182 |
| |
181 | 183 |
| |
| |||
198 | 200 |
| |
199 | 201 |
| |
200 | 202 |
| |
201 |
| - | |
202 |
| - | |
203 |
| - | |
204 |
| - | |
| 203 | + | |
205 | 204 |
| |
| 205 | + | |
| 206 | + | |
206 | 207 |
| |
207 | 208 |
| |
208 | 209 |
| |
| |||
212 | 213 |
| |
213 | 214 |
| |
214 | 215 |
| |
215 |
| - | |
| 216 | + | |
216 | 217 |
| |
217 |
| - | |
218 |
| - | |
| 218 | + | |
| 219 | + | |
219 | 220 |
| |
220 |
| - | |
| 221 | + | |
221 | 222 |
| |
222 | 223 |
| |
223 |
| - | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
224 | 228 |
| |
225 | 229 |
| |
226 | 230 |
| |
| |||
243 | 247 |
| |
244 | 248 |
| |
245 | 249 |
| |
246 |
| - | |
| 250 | + | |
247 | 251 |
| |
248 |
| - | |
| 252 | + | |
249 | 253 |
| |
250 | 254 |
| |
251 | 255 |
| |
252 | 256 |
| |
253 | 257 |
| |
254 |
| - | |
| 258 | + | |
255 | 259 |
| |
256 | 260 |
| |
257 |
| - | |
258 |
| - | |
259 |
| - | |
260 |
| - | |
261 |
| - | |
262 |
| - | |
263 |
| - | |
264 |
| - | |
265 | 261 |
| |
266 | 262 |
| |
267 | 263 |
| |
| |||
282 | 278 |
| |
283 | 279 |
| |
284 | 280 |
| |
285 |
| - | |
286 |
| - | |
287 |
| - | |
288 |
| - | |
| 281 | + | |
289 | 282 |
| |
| 283 | + | |
| 284 | + | |
290 | 285 |
| |
291 | 286 |
| |
292 | 287 |
| |
| |||
296 | 291 |
| |
297 | 292 |
| |
298 | 293 |
| |
299 |
| - | |
| 294 | + | |
300 | 295 |
| |
301 |
| - | |
302 |
| - | |
| 296 | + | |
| 297 | + | |
303 | 298 |
| |
304 |
| - | |
| 299 | + | |
305 | 300 |
| |
306 | 301 |
| |
307 |
| - | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
308 | 306 |
| |
309 | 307 |
| |
310 | 308 |
| |
|
0 commit comments
Comments
(0)