Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add internal API for fast module access from heap type methods #101476

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
erlend-aasland opened this issue Jan 31, 2023 · 1 comment · Fixed by #101477 or #102188
Closed

Add internal API for fast module access from heap type methods #101476

erlend-aasland opened this issue Jan 31, 2023 · 1 comment · Fixed by #101477 or #102188
Labels
extension-modules C modules in the Modules dir performance Performance or resource usage topic-C-API type-feature A feature request or enhancement

Comments

@erlend-aasland
Copy link
Contributor

erlend-aasland commented Jan 31, 2023

See topic on Discourse.

For CPython internal usage, we've got _PyModule_GetState, which is a fast variant of PyModule_GetState, the module check in the latter is simply an assert in the former.

For PyType_GetModuleState, there are three ifs (two of them implicitly in PyType_GetModule):

  1. check that the given type is a heap type
  2. check that the given type has an associated module
  3. check that the result of PyType_GetModule is not NULL

For stdlib core extension modules, all of these conditions are always true (AFAIK). With a fast static inlined variant, for example _PyType_GetModuleState, with a fast variant of PyType_GetModule inlined, where all three conditions are assert()ed, we can speed up a heap type methods that need to access module state.

Linked PRs

@erlend-aasland erlend-aasland added type-feature A feature request or enhancement performance Performance or resource usage extension-modules C modules in the Modules dir topic-C-API labels Jan 31, 2023
erlend-aasland added a commit to erlend-aasland/cpython that referenced this issue Jan 31, 2023
For fast module state access from heap type methods.
@erlend-aasland erlend-aasland linked a pull request Jan 31, 2023 that will close this issue
@gpshead
Copy link
Member

gpshead commented Feb 4, 2023

relevant discuss thread: https://discuss.python.org/t/a-fast-variant-of-pytype-getmodulestate/23377

i left a question on the PR regarding the API name (ALL_CAPS or not for in the API name to be similar to other fast unchecked APIs).

@erlend-aasland erlend-aasland changed the title Add _PyType_GetModuleState for fast module access from heap type methods Add internal API for fast module access from heap type methods Feb 6, 2023
miss-islington pushed a commit that referenced this issue Feb 23, 2023
For fast module state access from heap type methods.
erlend-aasland added a commit to erlend-aasland/cpython that referenced this issue Feb 23, 2023
JelleZijlstra pushed a commit to JelleZijlstra/cpython that referenced this issue Sep 10, 2024
For fast module state access from heap type methods.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension-modules C modules in the Modules dir performance Performance or resource usage topic-C-API type-feature A feature request or enhancement
Projects
None yet
2 participants