Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 33.9k
bpo-45953: Statically allocate the main interpreter (and initial thread state).#29883
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
bpo-45953: Statically allocate the main interpreter (and initial thread state). #29883
Uh oh!
There was an error while loading. Please reload this page.
Conversation
ericsnowcurrently commented Dec 1, 2021 • edited by bedevere-bot
Loading Uh oh!
There was an error while loading. Please reload this page.
edited by bedevere-bot
Uh oh!
There was an error while loading. Please reload this page.
| int | ||
| _PyEval_InitState(struct_ceval_state*ceval) | ||
| void | ||
| _PyEval_InitState(struct_ceval_state*ceval, PyThread_type_lockpending_lock) |
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.
Would this be a good opportunity to remove this function?
The _pending_calls struct belongs on the interpreter state, not on the ceval as only the main interpreter can handle them.
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.
There's enough going on in this PR that I'd rather not.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
markshannon left a comment
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.
A couple of tests have been inverted.
bedevere-bot commented Dec 2, 2021
When you're done making the requested changes, leave the comment: |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Include/internal/pycore_interp.h Outdated
| } _preallocated; | ||
| }; | ||
| #define_PyInterpreterState_INIT \ |
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.
This is only used once, please remove it.
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.
FYI, I brought this back to avoid so much nesting and clutter in _PyRuntimeState_INIT.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| } _preallocated; | ||
| } _PyRuntimeState; | ||
| #define_PyRuntimeState_INIT \ |
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.
Might as well remove this as well. It is also only used once.
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.
Should _Py_global_objects_INIT also move? It's pretty big and likely to get much bigger.
ericsnowcurrentlyJan 10, 2022 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
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.
Actually, _PyRuntimeState_INIT is used twice.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
ericsnowcurrently commented Jan 12, 2022
With basically all feedback addressed I plan on merging this soon, to unblock other changes I have waiting. If I missed something, I'd be glad to address it in a follow-up PR. |
gvanrossum commented Jan 12, 2022 via email
Fine with me. …On Wed, Jan 12, 2022 at 2:56 PM Eric Snow ***@***.***> wrote: With basically all feedback addressed I plan on merging this soon, to unblock other changes I have waiting. If I missed something, I'd be glad to address it in a follow-up PR. — Reply to this email directly, view it on GitHub <#29883 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAWCWMXNEYDUC6YIRLTJAEDUVYBIXANCNFSM5JFJMYAA> . Triage notifications on the go with GitHub Mobile for iOS <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android <https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>. You are receiving this because you are subscribed to this thread.Message ID: ***@***.***> -- --Guido van Rossum (python.org/~guido) |
As of CPython 3.11 (via python/cpython#29883) stdbool.h is now included in Python.h so do attempt to redefine bool/true/false.
As of CPython 3.11 (via python/cpython#29883) stdbool.h is now included in Python.h so do attempt to redefine bool/true/false.
Currently the main interpreter is allocated on the heap during runtime initialization. Here we are instead embedding it into
_PyRuntimeState, which means it is statically allocated as part of the_PyRuntimeglobal. The same goes for the initial thread state (of each interpreter, including the main one). Consequently there are fewer allocations during runtime/interpreter init, fewer possible failures, and better memory locality.FYI, this also helps efforts to consolidate globals, which in turns helps work on subinterpreter isolation.
https://bugs.python.org/issue45953