Uh oh!
There was an error while loading. Please reload this page.
gh-72902: improve Fraction(str) speed (don't use regexp's) - #133994
gh-72902: improve Fraction(str) speed (don't use regexp's)#133994skirpichev wants to merge 13 commits into
Conversation
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as resolved.
This comment was marked as resolved.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Co-authored-by: Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de>
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
3687e34 to
05e9110Compare
This comment was marked as resolved.
This comment was marked as resolved.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
eendebakpt
left a comment
There was a problem hiding this comment.
@skirpichev Could you also add a test case for Fraction('232e\t2') (this should fail). One optimization I tried passes all the tests, but fails on this one.
Tests pass, and all paths in the new code are needed, so approving. The new code is not very easy to read, but neither is the regular expression that is currently in main.
skirpichev
commented
May 19, 2025
Done.
I think that the later is more clear. Also, it has more nice tracebacks. So, I'm still not sure about this. Speed gain is x2 at most. Maybe regexps can be eventually optimized? |
serhiy-storchaka
commented
May 19, 2025
I was surprised that manual parsing is faster than a regexp-based approach. The regular expression is not optimal, so I tried to optimize it, but the benefit was minuscule. The regexp engine needs to be optimized. Can we please wait a few months with these changes while I try to optimize the regexp engine for such case? This seems so typical that a lot of code would benefit from optimization. |
skirpichev
commented
May 19, 2025
But not too much.
Sure. I'm not familiar with the regexp module code and I would be interested in such fix, if it's possible at all. BTW, so far this pr was not approved by core dev. @serhiy-storchaka, but what about other change, i.e. moving down numbers.Rational check? Maybe I should factor out this to a separate pr? See benchmarks (third column) and my arguments for this. |
skirpichev
commented
May 20, 2025
Ok, now this has only optimization for str inputs. Other goes to #134320 |
This PR is stale because it has been open for 30 days with no activity. |
Documentation build overview
482 files changed · |
For reviewers. I'm not sure if it worth (code seems more complex, IMO), but speedup for string parsing seems noticeable (1.3-1.5x).
Details