8000 Centralize power caching in `_pylong.py` · Issue #118610 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

Centralize power caching in _pylong.py #118610

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

Closed
tim-one opened this issue May 5, 2024 · 0 comments · Fixed by #118611
Closed

Centralize power caching in _pylong.py #118610

tim-one opened this issue May 5, 2024 · 0 comments · Fixed by #118611
Assignees
Labels
performance Performance or resource usage stdlib Python modules in the Lib dir

Comments

@tim-one
Copy link
Member
tim-one commented May 5, 2024

Proposal:

A number of functions in _pylong.py craft their own schemes to cache costly ** results. This complicates their code, and all of them end up doing more work than necessary.

So I want to add a new internal compute_powers() function that computes all and only the powers needed in advance, and returns a dict recording the results. It should speed things, but not by much (the time is dominated by how long it takes to compute the single largest power needed). The real point is code simplification.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

@tim-one tim-one added performance Performance or resource usage stdlib Python modules in the Lib dir labels May 5, 2024
@tim-one tim-one self-assigned this May 6, 2024
@tim-one tim-one linked a pull request May 6, 2024 that will close this issue
tim-one added a commit that referenced this issue May 8, 2024
A new `compute_powers()` function computes all and only the powers of the base the various base-conversion functions need, as efficiently as reasonably possible (turns out that invoking `**`is needed at most once). This typically gives a few % speedup, but the primary point is to simplify the base-conversion functions, which no longer need their own, ad hoc, and less efficient power-caching schemes.

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
SonicField pushed a commit to SonicField/cpython that referenced this issue May 8, 2024
)

A new `compute_powers()` function computes all and only the powers of the base the various base-conversion functions need, as efficiently as reasonably possible (turns out that invoking `**`is needed at most once). This typically gives a few % speedup, but the primary point is to simplify the base-conversion functions, which no longer need their own, ad hoc, and less efficient power-caching schemes.

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance or resource usage stdlib Python modules in the Lib dir
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant
0