This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author tim.peters
Recipients tim.peters
Date 2019-08-15.02:30:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1565836245.18.0.379877186731.issue37863@roundup.psfhosted.org>
In-reply-to
Content
Recording before I forget.  These are easy:

1. As the comments note, cache the hash code.

2. Use the new (in 3.8) pow(denominator, -1, modulus) to get the inverse instead of raising to the modulus-2 power.  Should be significantly faster.  If not, the new "-1" implementation should be changed ;-)  Will require catching ValueError in case the denom is a multiple of the modulus.

3. Instead of multiplying by the absolute value of the numerator, multiply by the hash of the absolute value of the numerator.  That changes the multiplication, and the subsequent modulus operation, from unbounded-length operations to short bounded-length ones.  Hashing the numerator on its own should be significantly faster, because the int hash doesn't require any multiplies or divides regardless of how large the numerator is.

None of those should change any computed results.
History
Date User Action Args
2019-08-15 02:30:45tim.peterssetrecipients: + tim.peters
2019-08-15 02:30:45tim.peterssetmessageid: <1565836245.18.0.379877186731.issue37863@roundup.psfhosted.org>
2019-08-15 02:30:45tim.peterslinkissue37863 messages
2019-08-15 02:30:44tim.peterscreate