aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/path/allpaths.c
diff options
context:
space:
mode:
authorDavid Rowley <drowley@postgresql.org>2022-12-04 16:18:18 +1300
committerDavid Rowley <drowley@postgresql.org>2022-12-04 16:18:18 +1300
commit6b423ec677d67c120d13a865fe3962985f0104c8 (patch)
tree865f9c3cdf1655466c8be1132d15b35b074c5288 /src/backend/optimizer/path/allpaths.c
parent29452de7341b0effbc275d7e139ade83cebda69f (diff)
downloadpostgresql-6b423ec677d67c120d13a865fe3962985f0104c8.tar.gz
postgresql-6b423ec677d67c120d13a865fe3962985f0104c8.zip
Improve performance of pg_strtointNN functions
Experiments have shown that modern versions of both gcc and clang are unable to fully optimize the multiplication by 10 that we're doing in the pg_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 be due to the overflow checking that we're doing. Without the overflow checks, both those compilers switch to a more efficient method of multiplying by 10. In absence of overflow concern, integer multiplication by 10 can be done by bit-shifting left 3 places to multiply by 8 and then adding the original value twice. To allow compilers this flexibility, here we adjust the code so that we accumulate the number as an unsigned version of the type and remove the use of pg_mul_sNN_overflow() and pg_sub_sNN_overflow(). The overflow checking can be done simply by checking if the accumulated value has gone beyond a 10th of the maximum *signed* value for the given type. If it has then the accumulation of the next digit will cause an overflow. After this is done, we do a final overflow check before converting the unsigned version of the number back to its signed counterpart. Testing has shown about an 8% speedup of a COPY into a table containing 2 INT columns. Author: David Rowley, Dean Rasheed Discussion: https://postgr.es/m/CAApHDvrL6_+wKgPqRHr7gH_6xy3hXM6a3QCsZ5ForurjDFfenA@mail.gmail.com Discussion: https://postgr.es/m/CAApHDvrdYByjfj-=WbmVNFgmVZg88-dE7heukw8p55aJ+W=qxQ@mail.gmail.com
Diffstat (limited to 'src/backend/optimizer/path/allpaths.c')
0 files changed, 0 insertions, 0 deletions