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-132312: Significantly reduce thread state lookups in the interpreter by ZeroIntensity · Pull Request #151453 · python/cpython

Conversation

@ZeroIntensity

@ZeroIntensity ZeroIntensity commented Jun 13, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

This does a lot of refactoring to avoid repeated _PyThreadState_GET calls in hot code paths (primarily the eval loop + common object operations).

Most of the changes here are mechanical, but I did have to make some more convoluted changes to make this robust (such as the addition of _Py_DECREF and such).

  • Issue: Add a PyThreadState * parameter (almost) everywhere #132312

Sorry, something went wrong.

Uh oh!

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

All reactions
ZeroIntensity added 7 commits June 13, 2026 12:19
@ZeroIntensity
Some initial stuff.
05a986a
@ZeroIntensity
Change some call API things.
c80ffc6
@ZeroIntensity
Avoid calls to _PyThreadState_GET() in the interpreter loop.
b5585cc
@ZeroIntensity
Avoid more lookups via decrefs.
14c9236
@ZeroIntensity
More decref stuff.
efcfaff
@ZeroIntensity
A few adjustments.
5f702e5
@ZeroIntensity
Fix free threading.
77d8f43
@bedevere-app bedevere-app Bot mentioned this pull request Jun 13, 2026
Add a PyThreadState * parameter (almost) everywhere #132312
Open
ZeroIntensity added 3 commits June 13, 2026 14:39
@ZeroIntensity
Remove inlining changes.
127e768
@ZeroIntensity
Fix _PyObject_Call redefinition.
8931a67
@ZeroIntensity
Oh how I love having 50 different implementations of Py_DECREF
e880b9c
@ZeroIntensity ZeroIntensity added the skip news label Jun 13, 2026
ZeroIntensity added 3 commits June 13, 2026 14:54
@ZeroIntensity
Use PyAPI_FUNC for _PyObject_Call
004108d
@ZeroIntensity
Fix vararg passing in PyErr_FormatUnraisable.
03a8351
@ZeroIntensity
Fix typo.
b915b43
@picnixz

picnixz commented Jun 14, 2026

Copy link
Copy Markdown
Member

Do you have some numbers on how much we gain with this dance?

All reactions

Sorry, something went wrong.

Uh oh!

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

@ZeroIntensity

ZeroIntensity commented Jun 14, 2026

Copy link
Copy Markdown
Member Author

Nothing conclusive yet, no.

All reactions

Sorry, something went wrong.

Uh oh!

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

@ZeroIntensity

ZeroIntensity commented Jun 14, 2026

Copy link
Copy Markdown
Member Author

I'm having a lot of trouble getting consistent benchmarks, unfortunately. My system seems to be too jittery to get a reliable result. I also don't know why the JIT CI is failing on Windows.

@Fidget-Spinner -- do you have advice for either of these?

All reactions

Sorry, something went wrong.

Uh oh!

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

@Fidget-Spinner

Fidget-Spinner commented Jun 14, 2026

Copy link
Copy Markdown
Member

@ZeroIntensity JIT on Windows requires whatever is used in bytecodes.c to be an exported symbol. In this case it's complaining memcpy is not available. Are you using that? If so, you need to add the relevant header to template.c

All reactions

Sorry, something went wrong.

Uh oh!

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

@ZeroIntensity

ZeroIntensity commented Jun 14, 2026

Copy link
Copy Markdown
Member Author

I didn't add anything that uses memcpy in this PR, but shouldn't functions from the C stdlib be considered exported anyway?

All reactions

Sorry, something went wrong.

Uh oh!

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

@Fidget-Spinner

Fidget-Spinner commented Jun 14, 2026

Copy link
Copy Markdown
Member

It could be indirectly used as well through an inlined function. In any case, unless string.h is included by Python.h or the other pycores by default it wont be included https://github.com/python/cpython/blob/main/Tools/jit/template.c

All reactions

Sorry, something went wrong.

Uh oh!

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

@ZeroIntensity
Add string.h to template.c
ee2c28a
@github-actions

github-actions Bot commented Sep 17, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 90 days with no activity.

All reactions

Sorry, something went wrong.

Uh oh!

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

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@Fidget-Spinner Fidget-Spinner Awaiting requested review from Fidget-Spinner Fidget-Spinner will be requested when the pull request is marked ready for review Fidget-Spinner is a code owner
@ericsnowcurrently ericsnowcurrently Awaiting requested review from ericsnowcurrently ericsnowcurrently will be requested when the pull request is marked ready for review ericsnowcurrently is a code owner
@FFY00 FFY00 Awaiting requested review from FFY00 FFY00 will be requested when the pull request is marked ready for review FFY00 is a code owner
@brandtbucher brandtbucher Awaiting requested review from brandtbucher brandtbucher will be requested when the pull request is marked ready for review brandtbucher is a code owner
@diegorusso diegorusso Awaiting requested review from diegorusso diegorusso will be requested when the pull request is marked ready for review diegorusso is a code owner
@brettcannon brettcannon Awaiting requested review from brettcannon brettcannon will be requested when the pull request is marked ready for review brettcannon is a code owner
@ncoghlan ncoghlan Awaiting requested review from ncoghlan ncoghlan will be requested when the pull request is marked ready for review ncoghlan is a code owner
@warsaw warsaw Awaiting requested review from warsaw warsaw will be requested when the pull request is marked ready for review warsaw is a code owner
@kumaraditya303 kumaraditya303 Awaiting requested review from kumaraditya303 kumaraditya303 will be requested when the pull request is marked ready for review kumaraditya303 is a code owner
@markshannon markshannon Awaiting requested review from markshannon markshannon will be requested when the pull request is marked ready for review markshannon is a code owner
@methane methane Awaiting requested review from methane methane will be requested when the pull request is marked ready for review methane is a code owner

Uh oh!

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

Assignees

No one assigned

Labels

skip news stale Stale PR or inactive for long period of time.

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

@ZeroIntensity @picnixz @Fidget-Spinner
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.