-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-72902: improve Fraction(str) speed (don't use regexp's) #133994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: Wolfgang Maier <[email protected]>
Co-authored-by: Pieter Eendebak <[email protected]>
The added code complexity is not too bad imo. But how often is the fraction parsing of strings a bottleneck? (i have no good answer here). And how import is There a few corner cases where behavior is different. For example in this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The large part of the speed up is due to moving the Rational check. This makes Fraction -> Fraction slower.
We must put correctness ahead of speed. Fraction('0x10/0b101')
See #134010 which adds new tests. |
Thanks, good points. I'll try to fix this.
Seems to be a good outcome of the original issue for me. |
For reviewers. I'm not sure if it worth (code seems more complex, IMO), but speedup for string parsing seems noticeable (1.5-2x). Partially due to moving down branch with numbers.Rational check (IMO, that does make sense), but mostly due to removing regexps.