GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-140544: store pointer to interpreter state as a thread local for fast access by kumaraditya303 · Pull Request #140573 · python/cpython

Conversation

@kumaraditya303

@kumaraditya303 kumaraditya303 commented Oct 25, 2025 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor
  • Issue: Store current interpreter as a thread local variable #140544

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
kumaraditya303 added 2 commits October 24, 2025 20:03
@kumaraditya303
use tls for interp
0ee4aba
@kumaraditya303
use fast access for freelist
04318d0
@kumaraditya303
kumaraditya303 requested review from ZeroIntensity and ericsnowcurrently as code owners October 25, 2025 03:14
@bedevere-app bedevere-app Bot mentioned this pull request Oct 25, 2025
Store current interpreter as a thread local variable #140544
Closed
@bedevere-app bedevere-app Bot added the awaiting core review label Oct 25, 2025
@kumaraditya303
cleanup 1
7115c75
@kumaraditya303
kumaraditya303 force-pushed the interp-tls branch from 428d3e0 to 7115c75 Compare October 25, 2025 05:00
kumaraditya303 and others added 4 commits October 25, 2025 10:31
@kumaraditya303
add back assertion
c6a7f91
@kumaraditya303
fix build
40407f7
@kumaraditya303
fix globals check
a42e973
@blurb-it
📜🤖 Added by blurb_it.
a2b1487
ZeroIntensity
ZeroIntensity reviewed Oct 25, 2025
View reviewed changes

@ZeroIntensity ZeroIntensity left a comment

Copy link
Copy Markdown
Member

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.

The core change looks good. Mostly nitpicks from me.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Misc/NEWS.d/next/Core_and_Builtins/2025-10-25-07-25-52.gh-issue-140544.lwjtQe.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/pystate.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Include/internal/pycore_pystate.h Resolved

Uh oh!

There was an error while loading. Please reload this page.

kumaraditya303 added 2 commits October 25, 2025 19:26
@kumaraditya303
review
2b3d15a
@kumaraditya303
improve comment
2dc93d3
ZeroIntensity
ZeroIntensity approved these changes Oct 25, 2025
View reviewed changes

@ZeroIntensity ZeroIntensity left a comment

Copy link
Copy Markdown
Member

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.

LGTM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Oct 25, 2025
@kumaraditya303
kumaraditya303 merged commit ef4665f into python:main Oct 25, 2025
4 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label Oct 25, 2025
@kumaraditya303
kumaraditya303 deleted the interp-tls branch October 25, 2025 14:26
cdce8p
cdce8p reviewed Oct 26, 2025
View reviewed changes
Comment thread Include/internal/pycore_pystate.h
_Py_EnsureTstateNotNULL(tstate);
#endif
return tstate->interp;
#if !defined(Py_BUILD_CORE_MODULE)

@cdce8p cdce8p Oct 26, 2025

Copy link
Copy Markdown
Contributor

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 this be

#if defined(HAVE_THREAD_LOCAL) && !defined(Py_BUILD_CORE_MODULE)

instead?

When testing the current main against mypyc, I'm seeing a new error message

In file included from /.../mypy/mypyc/lib-rt/misc_ops.c:1137:
In file included from /.../cpython/Include/internal/pycore_object.h:12:
In file included from /.../cpython/Include/internal/pycore_gc.h:12:
/.../cpython/Include/internal/pycore_pystate.h:213:12: error: use of undeclared identifier '_Py_tss_interp'
    return _Py_tss_interp;
           ^
1 error generated.

Mypyc does use some of the internal headers. In particular

#define Py_BUILD_CORE
...
#include "internal/pycore_object.h"

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@kumaraditya303 kumaraditya303 Oct 26, 2025

Copy link
Copy Markdown
Contributor Author

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.

I guess it is because mypyc doesn't define HAVE_THREAD_LOCAL which is defined when python is built, does #140623 fixes it for you?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ZeroIntensity ZeroIntensity Oct 26, 2025

Copy link
Copy Markdown
Member

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.

I think we should just remove the check for HAVE_THREAD_LOCAL on line 92.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@cdce8p cdce8p Oct 26, 2025

Copy link
Copy Markdown
Contributor

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.

I guess it is because mypyc doesn't define HAVE_THREAD_LOCAL which is defined when python is built, does #140623 fixes it for you?

Yes, that works.

I think we should just remove the check for HAVE_THREAD_LOCAL on line 92.

Guess, this would work too.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
StanFromIreland pushed a commit to StanFromIreland/cpython that referenced this pull request Dec 6, 2025
@kumaraditya303 @StanFromIreland
pythongh-140544: store pointer to interpreter state as a thread local…
4c3c087
… for fast access (python#140573)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ZeroIntensity ZeroIntensity ZeroIntensity approved these changes
@ericsnowcurrently ericsnowcurrently Awaiting requested review from ericsnowcurrently ericsnowcurrently is a code owner
+1 more reviewer
@cdce8p cdce8p cdce8p left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@kumaraditya303 @cdce8p @ZeroIntensity
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.