Skip to content
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

gh-118750: Asymptotically faster int(string) #118751

Merged
merged 112 commits into from May 19, 2024
Merged

gh-118750: Asymptotically faster int(string) #118751

merged 112 commits into from May 19, 2024

Conversation

tim-one
Copy link
Member

@tim-one tim-one commented May 8, 2024

Adding new, but unsued, _dec_str_to_int_inner(), + discussion.

@tim-one tim-one linked an issue May 8, 2024 that may be closed by this pull request
Lib/_pylong.py Outdated Show resolved Hide resolved
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
@nineteendo
Copy link
Contributor

Skip news?

Lib/_pylong.py Outdated Show resolved Hide resolved
Lib/_pylong.py Outdated Show resolved Hide resolved
tim-one and others added 2 commits May 8, 2024 12:25
Co-authored-by: sstandre <43125375+sstandre@users.noreply.github.com>
Co-authored-by: sstandre <43125375+sstandre@users.noreply.github.com>
@tim-one
Copy link
Member Author

tim-one commented May 8, 2024

Skip news?

Premature, I think. It's possible that a later version may become actively used.

@nineteendo
Copy link
Contributor

We only need a news entry for user facing changes. When the faster integer conversion is eventually implemented, you'll be credited.

@tim-one
Copy link
Member Author

tim-one commented May 8, 2024

Yes, I understand that. I'm saying that it's possible this will become a "user-facing" change soon. I already have a newer version (not yet checked in) that's much better. Mucking with labels is, IMO, a minor waste of time at this point.

@nineteendo
Copy link
Contributor

Sorry, I'm just trying to help. I thought you didn't mean in the near future.

@tim-one
Copy link
Member Author

tim-one commented May 8, 2024

No problem! Things change: I originally thought this was far from being ready, but that's been changing rapidly.

… did very much better than I recalled. So moving to that instead. The crossover point is "only" about 3.4 million digits now, far smaller.
@tim-one
Copy link
Member Author

tim-one commented May 8, 2024

A cute mystery: I noticed that converting a string representing an int a little smaller than a power of 256 took about 3x longer than one a little larger than that power. Turns out there's "a reason" for that: in the latter case, the n inner() sees is frequently 0, so it cuts back to a mere 8 digits of precision to compute the integer quotient. In the former case, n is usually chock full o' 1 bits, so the precision is only cut in half.

Add a int<->str test for a truly large int (10 million digits),
which isn't currently tested. Bur regrtest will skip it unless
the "cpu" resource is enabled (e.g., via "-ucpu" on the cmdline).
@tim-one
Copy link
Member Author

tim-one commented May 19, 2024

Dear Lord, buildbots can be annoying 😉.

It's hard to be sure of things digging through the mountains of text files they save. Best guess is the failing boxes do not build the C _decimal module, so mostly (always?) time out running test_int. I took my best guess at that and changed the tests most likely to time out then to not run at all unless _decimal is available, and checked that in.

But most of the buildbots that failed are just sitting there, apparently doing nothing, and trying to "force" a new run just says the request is queued - but not running it.

Just 3 of these buildbots appeared to wake up and actually run again after that commit. Their tests all passed.

So my best guess is that the problem is fixed. But no way yet to be sure.

@python python deleted a comment from bedevere-bot May 19, 2024
@python python deleted a comment from bedevere-bot May 19, 2024
@python python deleted a comment from bedevere-bot May 19, 2024
@python python deleted a comment from bedevere-bot May 19, 2024
@python python deleted a comment from bedevere-bot May 19, 2024
@python python deleted a comment from bedevere-bot May 19, 2024
@python python deleted a comment from bedevere-bot May 19, 2024
@python python deleted a comment from bedevere-bot May 19, 2024
@python python deleted a comment from bedevere-bot May 19, 2024
@python python deleted a comment from bedevere-bot May 19, 2024
@python python deleted a comment from bedevere-bot May 19, 2024
@python python deleted a comment from bedevere-bot May 19, 2024
@python python deleted a comment from bedevere-bot May 19, 2024
@python python deleted a comment from bedevere-bot May 19, 2024
@python python deleted a comment from bedevere-bot May 19, 2024
@python python deleted a comment from bedevere-bot May 19, 2024
@python python deleted a comment from bedevere-bot May 19, 2024
@python python deleted a comment from bedevere-bot May 19, 2024
@python python deleted a comment from bedevere-bot May 19, 2024
@python python deleted a comment from bedevere-bot May 19, 2024
@python python deleted a comment from bedevere-bot May 19, 2024
@python python deleted a comment from bedevere-bot May 19, 2024
@python python deleted a comment from bedevere-bot May 19, 2024
@python python deleted a comment from bedevere-bot May 19, 2024
@python python deleted a comment from bedevere-bot May 19, 2024
@python python deleted a comment from bedevere-bot May 19, 2024
@python python deleted a comment from bedevere-bot May 19, 2024
@python python deleted a comment from bedevere-bot May 19, 2024
@python python deleted a comment from bedevere-bot May 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Asymptotically faster int(string)
9 participants