Issue 12080: decimal.py: performance in _power_exact (original) (raw)

Created on 2011-05-15 08:28 by skrah, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue12080.patch mark.dickinson,2011-05-22 13:51 review
issue12080_v2.patch mark.dickinson,2011-05-22 15:10 review
Messages (8)
msg136022 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2011-05-15 08:28
I found another performance issue in _power_exact: >>> Decimal(4) ** Decimal("-1.2e-999999999") ^CTraceback (most recent call last): File "", line 1, in File "/home/stefan/pydev/cpython/Lib/decimal.py", line 2343, in __pow__ ans = self._power_exact(other, context.prec + 1) File "/home/stefan/pydev/cpython/Lib/decimal.py", line 2098, in _power_exact ten_pow = 10**-ye KeyboardInterrupt This one is in the power operation in line 2098. There are several other places where huge integer powers are calculated if 'ye' is sufficiently large.
msg136044 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2011-05-15 18:37
Thanks for the report; I'll try to find some time to look at this. This isn't the first time that I've thought that it might be better just to abandon the aim of getting correctly-rounded results for pow.
msg136524 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2011-05-22 13:51
Here's a patch. Stefan, could you please review?
msg136536 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2011-05-22 15:10
Here's a slightly improved version that adds guards against computing 10**ye for large ye in the case y < 0, ye > 0.
msg137652 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-06-04 17:14
New changeset c3fe54781244 by Mark Dickinson in branch 'default': Issue #12080: Fix a performance issue in Decimal._power_exact that causes some corner-case Decimal.__pow__ calls to take an unreasonably long time. http://hg.python.org/cpython/rev/c3fe54781244
msg137653 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-06-04 17:24
New changeset 78d79499e7de by Mark Dickinson in branch '2.7': Issue #12080: Fix a performance issue in Decimal._power_exact that caused some corner-case Decimal.__pow__ calls to take an unreasonably long time. http://hg.python.org/cpython/rev/78d79499e7de
msg137654 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2011-06-04 17:25
Fixed for 3.3 and 2.7.
msg137655 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2011-06-04 17:59
Mark Dickinson <report@bugs.python.org> wrote: > Here's a patch. Stefan, could you please review? Mark, sorry for not replying earlier. The patch looks great. I've also tested the patch in practice: I ran 700,000,000 random tests with an exponent range of [-999999999, 999999999]. This took three days. Without the patch, this would have been impossible; the range had to be restricted to [-9999, 9999]. Unfortunately I got sidetracked reviewing the rest of the function (today I started out on a mechanical proof of the nth-root part). I *did* review the changes though, and I think they are correct.
History
Date User Action Args
2022-04-11 14:57:17 admin set github: 56289
2011-06-04 17:59:48 skrah set messages: +
2011-06-04 17:25:22 mark.dickinson set status: open -> closedresolution: fixedmessages: +
2011-06-04 17:24:24 python-dev set messages: +
2011-06-04 17:14:33 python-dev set nosy: + python-devmessages: +
2011-05-22 15:10:22 mark.dickinson set files: + issue12080_v2.patchmessages: +
2011-05-22 13:51:58 mark.dickinson set stage: commit review
2011-05-22 13:51:31 mark.dickinson set files: + issue12080.patchkeywords: + patchmessages: +
2011-05-15 21🔞54 vstinner set nosy: + vstinner
2011-05-15 18:57:54 rhettinger set nosy: + rhettinger
2011-05-15 18:37:22 mark.dickinson set assignee: mark.dickinsonmessages: +
2011-05-15 08:28:21 skrah create