forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit5be1dab
committed
Optimize pg_memory_is_all_zeros() in memutils.h
pg_memory_is_all_zeros() is currently implemented to do only abyte-per-byte comparison. While being sufficient for its existingcallers for pgstats entries, it could lead to performance regressionsshould it be used for larger memory areas, like 8kB blocks, or evenfuture commits.This commit optimizes the implementation of this function to be moreefficient for larger sizes, written in a way so that compilers canoptimize the code. This is portable across 32b and 64b architectures.The implementation handles three cases, depending on the size of theinput provided:* If less than sizeof(size_t), do a simple byte-by-byte comparison.* If between sizeof(size_t) and (sizeof(size_t) * 8 - 1):** Phase 1: byte-by-byte comparison, until the pointer is aligned.** Phase 2: size_t comparisons, with aligned pointers, up to the last aligned location possible.** Phase 3: byte-by-byte comparison, until the end location.* If more than (sizeof(size_t) * 8) bytes, this is the same as case 2except that an additional phase is placed between Phase 1 and Phase 2,with 8 * sizeof(size_t) comparisons using bitwise OR, to encouragecompilers to use SIMD instructions if available.The last improvement proves to be at least 3 times faster than thesize_t comparisons, which is something currently used for the all-zeropage check in PageIsVerifiedExtended().The optimization tricks that would encourage the use of SIMDinstructions have been suggested by David Rowley.Author: Bertrand DrouvotReviewed-by: Michael Paquier, Ranier VilelaDiscussion:https://postgr.es/m/CAApHDvq7P-JgFhgtxUPqhavG-qSDVUhyWaEX9M8_MNorFEijZA@mail.gmail.com1 parent7b88529 commit5be1dab
1 file changed
+116
-3
lines changedLines changed: 116 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
190 | 190 |
| |
191 | 191 |
| |
192 | 192 |
| |
| 193 | + | |
| 194 | + | |
193 | 195 |
| |
194 | 196 |
| |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
195 | 217 |
| |
196 | 218 |
| |
197 | 219 |
| |
198 | 220 |
| |
199 |
| - | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
200 | 270 |
| |
201 |
| - | |
| 271 | + | |
| 272 | + | |
202 | 273 |
| |
203 |
| - | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
204 | 309 |
| |
205 | 310 |
| |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
206 | 319 |
| |
207 | 320 |
| |
208 | 321 |
| |
|
0 commit comments
Comments
(0)