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-143732: SEND specialization by markshannon · Pull Request #148963 · python/cpython

Conversation

@markshannon

@markshannon markshannon commented Apr 24, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

Adds 2 new specialized instructions:

  • SEND_VIRTUAL for sends to virtual iterators e.g lists and tuples
  • SEND_ASYNC_GEN for sends to async generators

Also, tweaks FOR_ITER_VIRTUAL so that SEND_VIRTUAL and FOR_ITER_VIRTUAL use equivalent guards

This is aimed more at JIT coverage, especially ensuring that we can trace through SEND instructions, than interpreter performance.

Performance is broadly neutral, but with improvements of 4-6% on the async_generators benchmark.

  • Issue: Broader specialization in the Specializing Adaptive Interpreter for better JIT performance #143732

Sorry, something went wrong.

Uh oh!

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

All reactions
@markshannon
SEND specialization. Adds 2 new specialized instructions:
1b0db04
* SEND_VIRTUAL: for sends to virtual iterators e.g lists and tuples
* SEND_ASYNC_GEN: for sends to async generators

Tweak FOR_ITER_VIRTUAL so that SEND_VIRTUAL and FOR_ITER_VIRTUAL use equivalent guards
@markshannon
markshannon requested review from Fidget-Spinner, brandtbucher, diegorusso, iritkatriel, savannahostrowski and tomasr8 as code owners April 24, 2026 15:45
@bedevere-app bedevere-app Bot added the awaiting core review label Apr 24, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Apr 24, 2026
Broader specialization in the Specializing Adaptive Interpreter for better JIT performance #143732
Open
@markshannon markshannon added the skip news label Apr 24, 2026
markshannon added 3 commits April 24, 2026 16:52
@markshannon
Bump magic number
5c0999c
@markshannon
Wrap PyIter_Send to return a struct for MSVC tailcall support
dddef02
@markshannon
Merge branch 'main' into send-specialization
f47c271
Fidget-Spinner
Fidget-Spinner reviewed Apr 26, 2026
View reviewed changes
Comment thread Tools/cases_generator/analyzer.py Outdated
"_PyStolenTuple_Free",
"PyObject_GC_UnTrack",
"_PyErr_ExceptionMatches",
"CALL_TP_ITERITEM",

@Fidget-Spinner Fidget-Spinner Apr 26, 2026

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 don't think this is right?

Sorry, something went wrong.

Uh oh!

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

All reactions

@markshannon markshannon Apr 27, 2026 •
edited
Loading

Uh oh!

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

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

It is correct in the normal build, but I'll need to exclude lists in the free-threading build.

Sorry, something went wrong.

Uh oh!

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

All reactions

@markshannon markshannon Apr 27, 2026 •
edited
Loading

Uh oh!

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

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

Special casing the free-threaded build is too messy, so I've removed this from the whitelist instead.

Sorry, something went wrong.

Uh oh!

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

All reactions
markshannon added 4 commits April 27, 2026 08:48
@markshannon
Disallow escaping calls in virtual iteration
6f8b048
@markshannon
Make sure we still specialize FOR_ITER_LIST on free-threading build
0879eda
@markshannon
Don't special case free-threading (it's too complex). Mark _tp_iterit…
0387f10
…em functions as escaping.
@markshannon
Merge branch 'main' into send-specialization
83bb3f4
@markshannon markshannon mentioned this pull request Apr 30, 2026
gh-142982 Implement _SEND_NON_GEN specialization #143977
Closed
@markshannon
Merge branch 'main' into send-specialization
1737f73
Fidget-Spinner
Fidget-Spinner approved these changes May 5, 2026
View reviewed changes

@Fidget-Spinner Fidget-Spinner 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, just two questions, feel free to merge after addressing them.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Objects/genobject.c
0, /* am_anext */
0, /* am_send */
.am_await = PyObject_SelfIter,
.am_send = _PyAsyncGenASend_Send,

@Fidget-Spinner Fidget-Spinner May 5, 2026

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.

Why this change?

Sorry, something went wrong.

Uh oh!

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

All reactions

@markshannon markshannon May 5, 2026

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

Otherwise, the send needs to go through a call to the send method. I don't know why this wasn't implemented before.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Python/ceval_macros.h Outdated
(PyLongObject *)PyStackRef_AsPyObjectBorrow(right)); \
}

#define CALL_TP_ITERITEM(ITER, INDEX) \

@Fidget-Spinner Fidget-Spinner May 5, 2026

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 know this is to make it non-escaping to the analyzer, but it would be clearer if you said CALL_TP_ITERITEM_NO_ESCAPE or something.

Sorry, something went wrong.

Uh oh!

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

All reactions

@markshannon markshannon May 5, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member 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 dropped the special meaning, to avoid problems with the free-threading build.
I'll just remove the macro, as it isn't doing anything useful any more.

I dropped it for the SAI. I'll update the name as you suggest for the JIT.

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 May 5, 2026
@markshannon
Mark calls to _tp_iteritem as possibly escaping
6b62032
@read-the-docs-community

read-the-docs-community Bot commented May 5, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #32544434 | 📁 Comparing 20c8cbe against main (618b726)

  🔍 Preview build  

80 files changed · + 2 added · ± 78 modified

+ Added

  • c-api/sentinel.html
  • c-api/slots.html

± Modified

  • glossary.html
  • c-api/concrete.html
  • c-api/extension-modules.html
  • c-api/index.html
  • c-api/lifecycle.html
  • c-api/module.html
  • c-api/perfmaps.html
  • c-api/stable.html
  • c-api/synchronization.html
  • c-api/type.html
  • and 68 more...
All reactions

Sorry, something went wrong.

Uh oh!

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

@markshannon
Clarify that calls _tp_iteritem are only treated as no-escapping in t…
20c8cbe
…he JIT
@markshannon
markshannon merged commit 70bd1c2 into python:main May 5, 2026
84 checks passed

Uh oh!

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

@bedevere-app bedevere-app Bot removed the awaiting merge label May 5, 2026
@ashm-dev ashm-dev mentioned this pull request Sep 27, 2026
Async generators create and discard a StopIteration exception for every yielded value #158304
Closed
@KowalskiThomas KowalskiThomas mentioned this pull request Oct 4, 2026
_SEND_ASYNC_GEN_TIER_TWO side exit corrupts the stack when an async generator returns #158804
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@Fidget-Spinner Fidget-Spinner Fidget-Spinner approved these changes
@tomasr8 tomasr8 Awaiting requested review from tomasr8 tomasr8 is a code owner
@savannahostrowski savannahostrowski Awaiting requested review from savannahostrowski
@brandtbucher brandtbucher Awaiting requested review from brandtbucher brandtbucher is a code owner
@diegorusso diegorusso Awaiting requested review from diegorusso diegorusso is a code owner
@iritkatriel iritkatriel Awaiting requested review from iritkatriel iritkatriel is a code owner

Uh oh!

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

Assignees

No one assigned

Labels

skip news

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.

2 participants

@markshannon @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.