Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

ericsnowcurrently
Copy link
Member

@ericsnowcurrentlyericsnowcurrently commentedDec 1, 2021
edited by bedevere-bot
Loading

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_PyRuntime global. 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

int
_PyEval_InitState(struct _ceval_state *ceval)
void
_PyEval_InitState(struct _ceval_state *ceval, PyThread_type_lock pending_lock)
Copy link
Member

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 theceval as only the main interpreter can handle them.

Copy link
MemberAuthor

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.

Copy link
Member

@markshannonmarkshannon left a 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
Copy link

When you're done making the requested changes, leave the comment:I have made the requested changes; please review again.

};

#define _PyInterpreterState_INIT \
Copy link
Member

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.

ericsnowcurrently reacted with thumbs up emoji
Copy link
MemberAuthor

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.

// because on Windows we only get a pointer type.
// All other pointers in PyThreadState are either
// populated lazily or change but default to NULL.
} _preallocated;
} _PyRuntimeState;

#define _PyRuntimeState_INIT \
Copy link
Member

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.

ericsnowcurrently reacted with thumbs up emoji
Copy link
MemberAuthor

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.

Copy link
MemberAuthor

@ericsnowcurrentlyericsnowcurrentlyJan 10, 2022
edited
Loading

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.

@ericsnowcurrently
Copy link
MemberAuthor

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
Copy link
Member

gvanrossum commentedJan 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)

@ericsnowcurrentlyericsnowcurrently merged commited57b36 intopython:mainJan 12, 2022
@ericsnowcurrentlyericsnowcurrently deleted the preallocate-main branchJanuary 12, 2022 23:28
tacaswell added a commit to tacaswell/typed_ast that referenced this pull requestJan 25, 2022
As of CPython 3.11 (viapython/cpython#29883) stdbool.his now included in Python.h so do attempt to redefine bool/true/false.
srittau pushed a commit to python/typed_ast that referenced this pull requestJan 25, 2022
As of CPython 3.11 (viapython/cpython#29883) stdbool.his now included in Python.h so do attempt to redefine bool/true/false.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@arhadthedevarhadthedevarhadthedev left review comments

@markshannonmarkshannonAwaiting requested review from markshannonmarkshannon is a code owner

Assignees

@markshannonmarkshannon

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

6 participants
@ericsnowcurrently@bedevere-bot@markshannon@gvanrossum@arhadthedev@the-knights-who-say-ni

[8]ページ先頭

©2009-2025 Movatter.jp