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

PyCode_GetCode could be faster #93382

Closed
Fidget-Spinner opened this issue May 31, 2022 · 0 comments · Fixed by #93383
Closed

PyCode_GetCode could be faster #93382

Fidget-Spinner opened this issue May 31, 2022 · 0 comments · Fixed by #93383
Labels
3.12 interpreter-core performance

Comments

@Fidget-Spinner
Copy link
Member

@Fidget-Spinner Fidget-Spinner commented May 31, 2022

This potentially affects tools like coverage.py. It also means anything using co_code in CPython frequently is significantly slower. Note that pre-3.11, most code would assume this operation is O(1), so it's probably called more often than we expect.

We should lazily initialise a hidden _co_code field and cache it there. Currently it creates a fresh bytes object on each co_code access. This is at best O(n).

@Fidget-Spinner Fidget-Spinner added the type-bug label May 31, 2022
@kumaraditya303 kumaraditya303 added performance and removed type-bug labels May 31, 2022
@Fidget-Spinner Fidget-Spinner changed the title PyCode_GetCode is really slow PyCode_GetCode could be faster May 31, 2022
@AA-Turner AA-Turner added interpreter-core 3.12 labels May 31, 2022
Fidget-Spinner added a commit that referenced this issue Jun 3, 2022
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Co-authored-by: Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com>
Fidget-Spinner added a commit to Fidget-Spinner/cpython that referenced this issue Jun 4, 2022
…nGH-93383)

Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Co-authored-by: Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 interpreter-core performance
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants