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 Sergey.Kirpichev
Recipients Sergey.Kirpichev
Date 2021-05-17.03:58:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1621223914.12.0.379949005457.issue44154@roundup.psfhosted.org>
In-reply-to
Content
The current version of the Fraction.__reduce__() method uses str(), which produces bigger dumps, esp. for large components.

C.f.:
>>> import random, pickle
>>> from fractions import Fraction as F
>>> random.seed(1); a = F(*random.random().as_integer_ratio())
>>> for proto in range(pickle.HIGHEST_PROTOCOL + 1):
...     print(len(pickle.dumps(a, proto)))
... 
71
70
71
71
77
77
>>> b = a**13
>>> for proto in range(pickle.HIGHEST_PROTOCOL + 1):
...     print(len(pickle.dumps(b, proto)))
... 
444
443
444
444
453
453

vs the attached patch:
>>> for proto in range(pickle.HIGHEST_PROTOCOL + 1):
...     print(len(pickle.dumps(a, proto)))
... 
71
68
49
49
59
59
>>> for proto in range(pickle.HIGHEST_PROTOCOL + 1):
...     print(len(pickle.dumps(b, proto)))
... 
444
441
204
204
214
214

Testing for non-default protocols was also added.  Let me know if all this does make sense as a PR.
History
Date User Action Args
2021-05-17 03:58:34Sergey.Kirpichevsetrecipients: + Sergey.Kirpichev
2021-05-17 03:58:34Sergey.Kirpichevsetmessageid: <1621223914.12.0.379949005457.issue44154@roundup.psfhosted.org>
2021-05-17 03:58:34Sergey.Kirpichevlinkissue44154 messages
2021-05-17 03:58:33Sergey.Kirpichevcreate