[issue44154] Optimize Fraction pickling

2021-05-23 Thread Raymond Hettinger
Raymond Hettinger added the comment: > Let me know if it's worth openning an issue with above improvement I don't think so. -- ___ Python tracker ___

[issue44154] Optimize Fraction pickling

2021-05-21 Thread Sergey B Kirpichev
Sergey B Kirpichev added the comment: On Thu, May 20, 2021 at 12:03:38AM +, Raymond Hettinger wrote: > Raymond Hettinger added the comment: > You're right that this won't work for decimal because it takes a > string constructor. A fancier reduce might do the trick but it would > involve m

[issue44154] Optimize Fraction pickling

2021-05-19 Thread Raymond Hettinger
Raymond Hettinger added the comment: You're right that this won't work for decimal because it takes a string constructor. A fancier reduce might do the trick but it would involve modifying the C code (no fun) as well as the Python code. Also, the conversion from decimal to string and back

[issue44154] Optimize Fraction pickling

2021-05-17 Thread Sergey B Kirpichev
Sergey B Kirpichev added the comment: Not sure why this wasn't closed after pr merging. If this was intentional - let me know and reopen. I'm less sure if something like this will work for a Decimal(). Perhaps, if the constructor will accept an integer as the value[1], not just a tuple of

[issue44154] Optimize Fraction pickling

2021-05-16 Thread Sergey B Kirpichev
Sergey B Kirpichev added the comment: > Oh yes - please do. Ok, I did. > It's not just pickle size - going through str() makes (un)pickling quadratic > time in both directions if components are large. Yeah, I noticed speedup too, but size was much more important for may application. BTW,

[issue44154] Optimize Fraction pickling

2021-05-16 Thread Tim Peters
Tim Peters added the comment: Oh yes - please do. It's not just pickle size - going through str() makes (un)pickling quadratic time in both directions if components are large. Pickle the component ints instead, and the more recent pickle protocol(s) can do both directions in linear time inst

[issue44154] Optimize Fraction pickling

2021-05-16 Thread Sergey B Kirpichev
Change by Sergey B Kirpichev : -- pull_requests: +24803 stage: -> patch review pull_request: https://github.com/python/cpython/pull/26186 ___ Python tracker ___ __

[issue44154] Optimize Fraction pickling

2021-05-16 Thread Raymond Hettinger
Raymond Hettinger added the comment: Yes, this looks reasonable. Go ahead with a PR. -- assignee: -> rhettinger nosy: +rhettinger type: -> performance ___ Python tracker __

[issue44154] Optimize Fraction pickling

2021-05-16 Thread Sergey B Kirpichev
New submission from Sergey B Kirpichev : 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_rat