bpo-45953: Statically allocate the main interpreter (and initial thread state).#29883
Conversation
| int | ||
| _PyEval_InitState(struct _ceval_state *ceval) | ||
| void | ||
| _PyEval_InitState(struct _ceval_state *ceval, PyThread_type_lock pending_lock) |
There was a problem hiding this comment.
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.
There's enough going on in this PR that I'd rather not.
markshannon
left a comment
There was a problem hiding this comment.
A couple of tests have been inverted.
|
When you're done making the requested changes, leave the comment: |
Include/internal/pycore_interp.h
Outdated
| } _preallocated; | ||
| }; | ||
|
|
||
| #define _PyInterpreterState_INIT \ |
There was a problem hiding this comment.
This is only used once, please remove it.
There was a problem hiding this comment.
FYI, I brought this back to avoid so much nesting and clutter in _PyRuntimeState_INIT.
| } _preallocated; | ||
| } _PyRuntimeState; | ||
|
|
||
| #define _PyRuntimeState_INIT \ |
There was a problem hiding this comment.
Might as well remove this as well. It is also only used once.
There was a problem hiding this comment.
Should _Py_global_objects_INIT also move? It's pretty big and likely to get much bigger.
There was a problem hiding this comment.
Actually, _PyRuntimeState_INIT is used twice.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
|
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. |
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