aboutsummaryrefslogtreecommitdiff
path: root/src/tutorial/syscat.source
diff options
context:
space:
mode:
authorDean Rasheed <dean.a.rasheed@gmail.com>2024-08-15 10:36:17 +0100
committerDean Rasheed <dean.a.rasheed@gmail.com>2024-08-15 10:36:17 +0100
commit8dc28d7eb868b6ce5a51614628bf46fc63c7e90c (patch)
tree12e3a1da781232d64eaae46700b76c95a228a432 /src/tutorial/syscat.source
parentc4e44224cf617c8cd33a734f888c045ac9575226 (diff)
downloadpostgresql-8dc28d7eb868b6ce5a51614628bf46fc63c7e90c.tar.gz
postgresql-8dc28d7eb868b6ce5a51614628bf46fc63c7e90c.zip
Optimise numeric multiplication using base-NBASE^2 arithmetic.
Currently mul_var() uses the schoolbook multiplication algorithm, which is O(n^2) in the number of NBASE digits. To improve performance for large inputs, convert the inputs to base NBASE^2 before multiplying, which effectively halves the number of digits in each input, theoretically speeding up the computation by a factor of 4. In practice, the actual speedup for large inputs varies between around 3 and 6 times, depending on the system and compiler used. In turn, this significantly reduces the runtime of the numeric_big regression test. For this to work, 64-bit integers are required for the products of base-NBASE^2 digits, so this works best on 64-bit machines, on which it is faster whenever the shorter input has more than 4 or 5 NBASE digits. On 32-bit machines, the additional overheads, especially during carry propagation and the final conversion back to base-NBASE, are significantly higher, and it is only faster when the shorter input has more than around 50 NBASE digits. When the shorter input has more than 6 NBASE digits (so that mul_var_short() cannot be used), but fewer than around 50 NBASE digits, there may be a noticeable slowdown on 32-bit machines. That seems to be an acceptable tradeoff, given the performance gains for other inputs, and the effort that would be required to maintain code specifically targeting 32-bit machines. Joel Jacobson and Dean Rasheed. Discussion: https://postgr.es/m/9d8a4a42-c354-41f3-bbf3-199e1957db97%40app.fastmail.com
Diffstat (limited to 'src/tutorial/syscat.source')
0 files changed, 0 insertions, 0 deletions