postgresql/src/include/utils
Michael Paquier 5be1dabd2a Optimize pg_memory_is_all_zeros() in memutils.h
pg_memory_is_all_zeros() is currently implemented to do only a
byte-per-byte comparison.  While being sufficient for its existing
callers for pgstats entries, it could lead to performance regressions
should it be used for larger memory areas, like 8kB blocks, or even
future commits.

This commit optimizes the implementation of this function to be more
efficient for larger sizes, written in a way so that compilers can
optimize the code.  This is portable across 32b and 64b architectures.

The implementation handles three cases, depending on the size of the
input 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 2
except that an additional phase is placed between Phase 1 and Phase 2,
with 8 * sizeof(size_t) comparisons using bitwise OR, to encourage
compilers to use SIMD instructions if available.

The last improvement proves to be at least 3 times faster than the
size_t comparisons, which is something currently used for the all-zero
page check in PageIsVerifiedExtended().

The optimization tricks that would encourage the use of SIMD
instructions have been suggested by David Rowley.

Author: Bertrand Drouvot
Reviewed-by: Michael Paquier, Ranier Vilela
Discussion: https://postgr.es/m/CAApHDvq7P-JgFhgtxUPqhavG-qSDVUhyWaEX9M8_MNorFEijZA@mail.gmail.com
2024-11-18 10:08:38 +09:00
..
.gitignore Generate automatically code and documentation related to wait events 2023-07-05 10:53:11 +09:00
acl.h Improve tracking of role dependencies of pg_init_privs entries. 2024-06-17 12:55:10 -04:00
aclchk_internal.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
array.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
arrayaccess.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
ascii.h Move is_valid_ascii() to ascii.h. 2024-01-29 12:08:57 -06:00
attoptcache.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
backend_progress.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
backend_status.h Rename some shared memory initialization routines 2024-08-29 09:46:21 +03:00
builtins.h Adjust populate_record_field() to handle errors softly 2024-01-24 15:04:33 +09:00
bytea.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
cash.h Convert *GetDatum() and DatumGet*() macros to inline functions 2022-09-27 20:50:21 +02:00
catcache.h For inplace update, send nontransactional invalidations. 2024-10-25 06:51:02 -07:00
combocid.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
conffiles.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
date.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
datetime.h Support TZ and OF format codes in to_timestamp(). 2024-01-25 17:47:08 -05:00
datum.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
dsa.h Allow specifying initial and maximum segment sizes for DSA. 2024-03-27 11:43:29 +09:00
dynahash.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
elog.h Don't advance origin during apply failure. 2024-08-21 09:22:32 +05:30
evtcache.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
expandeddatum.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
expandedrecord.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
float.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
fmgrtab.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
formatting.h Add SQL/JSON query functions 2024-03-21 17:07:03 +09:00
freepage.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
geo_decls.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
guc.h Apply PGDLLIMPORT markings to some GUC variables 2024-08-14 11:36:12 +02:00
guc_hooks.h Restrict accesses to non-system views and foreign tables during pg_dump. 2024-08-05 06:05:33 -07:00
guc_tables.h Rename COMPAT_OPTIONS_CLIENT to COMPAT_OPTIONS_OTHER. 2024-03-27 10:45:28 -04:00
help_config.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
hsearch.h Introduce hash_search_with_hash_value() function 2024-08-07 07:06:17 +03:00
index_selfuncs.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
inet.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
injection_point.h Fix typos and grammar in code comments and docs 2024-09-03 14:49:04 +09:00
inval.h Fix inplace update buffer self-deadlock. 2024-11-02 09:04:56 -07:00
json.h Optimize escaping of JSON strings 2024-07-27 23:46:07 +12:00
jsonb.h Add SQL/JSON query functions 2024-03-21 17:07:03 +09:00
jsonfuncs.h Make nullSemAction const, add 'const' decorators to related functions 2024-08-06 23:04:22 +03:00
jsonpath.h SQL/JSON: Correct jsonpath variable name matching 2024-06-19 15:22:06 +09:00
logtape.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
lsyscache.h ATTACH PARTITION: Don't match a PK with a UNIQUE constraint 2024-04-15 15:07:47 +02:00
memdebug.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
memutils.h Optimize pg_memory_is_all_zeros() in memutils.h 2024-11-18 10:08:38 +09:00
memutils_internal.h Introduce a bump memory allocator 2024-04-08 00:02:43 +12:00
memutils_memorychunk.h Enlarge bit-space for MemoryContextMethodID 2024-04-07 23:32:00 +12:00
meson.build Update copyright for 2024 2024-01-03 20:49:05 -05:00
multirangetypes.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
numeric.h Add functions to generate random numbers in a specified range. 2024-03-27 10:12:39 +00:00
palloc.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
partcache.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_crc.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_locale.h Simplify checking for xlocale.h 2024-10-01 07:23:45 -04:00
pg_lsn.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_rusage.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pgstat_internal.h Fix race conditions with drop of reused pgstats entries 2024-11-15 11:31:58 +09:00
pidfile.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
plancache.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
portal.h Update comment in portal.h. 2024-08-01 17:45:00 +09:00
ps_status.h Speedup and increase usability of set proc title functions 2023-02-20 16:18:27 +13:00
queryenvironment.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
rangetypes.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
regproc.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
rel.h Revert: Allow table AM to store complex data structures in rd_amcache 2024-04-11 16:02:49 +03:00
relcache.h Add pg_constraint rows for not-null constraints 2024-11-08 13:28:48 +01:00
relfilenumbermap.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
relmapper.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
relptr.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
reltrigger.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
resowner.h Harmonize function parameter names for Postgres 17. 2024-06-12 17:01:51 -04:00
rls.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
ruleutils.h Revert support for ALTER TABLE ... MERGE/SPLIT PARTITION(S) commands 2024-08-24 18:48:48 +03:00
sampling.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
selfuncs.h Enhance nbtree ScalarArrayOp execution. 2024-04-06 11:47:10 -04:00
sharedtuplestore.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
snapmgr.h Remove GlobalVisTestNonRemovable[Full]Horizon, not used anymore 2024-04-17 11:21:17 -07:00
snapshot.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
sortsupport.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
spccache.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
syscache.h For inplace update durability, make heap_update() callers wait. 2024-09-24 15:25:18 -07:00
timeout.h Introduce transaction_timeout 2024-02-15 23:56:12 +02:00
timestamp.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
tuplesort.h Harmonize function parameter names for Postgres 17. 2024-06-12 17:01:51 -04:00
tuplestore.h Adjust tuplestore stats API 2024-09-12 16:02:01 +12:00
typcache.h Avoid looping over all type cache entries in TypeCacheRelCallback() 2024-10-24 14:35:52 +03:00
tzparser.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
usercontext.h Perform logical replication actions as the table owner. 2023-04-04 11:25:23 -04:00
uuid.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
varbit.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
varlena.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
wait_event.h Add wait event type "InjectionPoint", a custom type like "Extension". 2024-06-27 19:21:05 -07:00
xid8.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
xml.h Update copyright for 2024 2024-01-03 20:49:05 -05:00