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-143414: Implement unique reference tracking for JIT, optimize unpacking of such tuples by reidenong · Pull Request #144300 · python/cpython

Conversation

@reidenong

@reidenong reidenong commented Jan 28, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor
  1. Implements unique reference tracking to references in the JIT Optimizer.
  2. Uses the unique reference tracking to eliminate unnecessary reference counting for uniquely referenced tuples. ex:
x, y, z = f()

Some notes:

  • Only implements the unique reference tracking (and relevant optimization) for tuples in _BUILD_TUPLE, to be extended to other objects in the future
  • Objects are deemed as not uniquely referenced when they are made aliases or duplicated, in uops of _LOAD_FAST_* and _COPY.

Would appreciate any feedback.
Thanks

  • Issue: JIT: Implement unique reference tracking in Tier 2 for reference count optimizations #143414

Sorry, something went wrong.

Uh oh!

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

cocolato reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@reidenong
Add unique reference tracking to JIT, optimize tuple unpacking
e4b7f51
@reidenong
reidenong requested review from Fidget-Spinner, markshannon, savannahostrowski and tomasr8 as code owners January 28, 2026 12:57
@bedevere-app bedevere-app Bot mentioned this pull request Jan 28, 2026
JIT: Implement unique reference tracking in Tier 2 for reference count optimizations #143414
Closed
@bedevere-app bedevere-app Bot added the awaiting review label Jan 28, 2026
reidenong and others added 2 commits January 28, 2026 20:58
@reidenong
Merge branch 'main' into branch-unique-reference-tracking
b32a8e2
@reidenong
Regenerate cases
7aeac0e
cocolato
cocolato reviewed Jan 28, 2026
View reviewed changes
Comment thread Python/optimizer_bytecodes.c Resolved

Uh oh!

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

@reidenong
Fix unique tuple unpacking checks
f8b7e4e
@reidenong

reidenong commented Jan 28, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

Discussed with @Fidget-Spinner, will reopen the PR after implementing PyStackRef_CLOSE_SPECIALIZED for _UNPACK_SEQUENCE_UNIQUE_TUPLE

All reactions

Sorry, something went wrong.

Uh oh!

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

@reidenong
reidenong marked this pull request as draft January 28, 2026 18:38
@bedevere-app bedevere-app Bot removed the awaiting review label Jan 28, 2026
reidenong added 2 commits January 29, 2026 18:47
@reidenong
Implement _PyTuple_ExactDealloc
37d7c4b
@reidenong
Rename symbol
7df2176
@reidenong
reidenong marked this pull request as ready for review January 29, 2026 11:04
@bedevere-app bedevere-app Bot added the awaiting review label Jan 29, 2026
@Fidget-Spinner

Fidget-Spinner commented Jan 29, 2026

Copy link
Copy Markdown
Member

Windows Ci failure looks possibly related, can you please look into it?

reidenong reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

reidenong and others added 4 commits January 30, 2026 10:59
@reidenong
Merge branch 'main' into branch-unique-reference-tracking
6f66c56
@reidenong
Merge branch 'main' into branch-unique-reference-tracking
b251825
@reidenong
Regenerate cases
bcd5654
@reidenong
Add alignment checking
acfa737
@reidenong
reidenong marked this pull request as draft January 31, 2026 06:39
@bedevere-app bedevere-app Bot removed the awaiting review label Jan 31, 2026
reidenong and others added 2 commits January 31, 2026 23:11
@reidenong
Change JIT reference tags to 2 bit scheme
a0fd9e2
@blurb-it
📜🤖 Added by blurb_it.
645776a
@reidenong
reidenong marked this pull request as ready for review January 31, 2026 16:36
@bedevere-app bedevere-app Bot added the awaiting review label Jan 31, 2026
Fidget-Spinner
Fidget-Spinner reviewed Jan 31, 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.

This is excellent. Just 2 comments, then I think it's safe to merge.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Include/internal/pycore_optimizer.h Resolved

Uh oh!

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

Comment thread Python/optimizer_bytecodes.c Outdated

op(_COPY, (bottom, unused[oparg-1] -- bottom, unused[oparg-1], top)) {
assert(oparg > 0);
bottom = PyJitRef_IsUnique(bottom) ? PyJitRef_StripReferenceInfo(bottom) : bottom;

@Fidget-Spinner Fidget-Spinner Jan 31, 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.

We only need to strip unique info here, not the borrow info too. This way we still get refcount elimination with the borrow.

Sorry, something went wrong.

Uh oh!

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

All reactions

@reidenong reidenong Feb 1, 2026

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 think this is consistent with the code?

If the ref is unique, we remove the unique tag, otherwise we leave it as is. Since a ref cannot be both unique and borrowed at the same time, borrowed/invalid refs will be maintained.

Sorry, something went wrong.

Uh oh!

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

All reactions

@Fidget-Spinner Fidget-Spinner Feb 1, 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.

Sounds good, thanks!

Sorry, something went wrong.

Uh oh!

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

All reactions
reidenong and others added 2 commits February 21, 2026 12:52
@reidenong
Regen cases
0b07ac4
@reidenong
Merge branch 'main' into branch-unique-reference-tracking
14e5d3d
@reidenong

reidenong commented Feb 21, 2026

Copy link
Copy Markdown
Contributor Author

I have made the requested changes; please review again. Thanks!

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app bedevere-app Bot added awaiting change review and removed awaiting changes labels Feb 21, 2026
@bedevere-app

bedevere-app Bot commented Feb 21, 2026

Copy link
Copy Markdown

Thanks for making the requested changes!

@markshannon: please review the changes made to this pull request.

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app
bedevere-app Bot requested a review from markshannon February 21, 2026 05:18
reidenong and others added 3 commits March 9, 2026 21:31
@reidenong
Merge branch 'main' into branch-unique-reference-tracking
8506038
@reidenong
Regen cases
d67617f
@reidenong
Merge branch 'main' into branch-unique-reference-tracking
100eeb5
@reidenong

reidenong commented Mar 9, 2026

Copy link
Copy Markdown
Contributor Author

@markshannon Hi mark, please take a look at this PR when you have the time. Thanks!

All reactions

Sorry, something went wrong.

Uh oh!

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

reidenong added 2 commits March 11, 2026 21:30
@reidenong
Merge branch 'main' into branch-unique-reference-tracking
e476061
@reidenong
Merge branch 'main' into branch-unique-reference-tracking
06a9ec1
@markshannon markshannon mentioned this pull request Mar 13, 2026
Convert more uops to leave their inputs on the stack to be cleaned up by _POP_TOP #145866
Open
@Fidget-Spinner

Fidget-Spinner commented Mar 22, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

@reidenong sorry can you please merge in main to this PR? I'll try to get this in this week.

All reactions

Sorry, something went wrong.

Uh oh!

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

Fidget-Spinner added 3 commits March 22, 2026 22:42
@Fidget-Spinner
Merge remote-tracking branch 'upstream/main' into pr/144300
6bce6b4
@Fidget-Spinner
Mark unique tuple freeing as non-escaping
89dc467
@Fidget-Spinner
fix a bugs in _COPY_FREE_VARS and frame creation
4e6c792
Fidget-Spinner
Fidget-Spinner approved these changes Mar 22, 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.

Nice!

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 change review labels Mar 22, 2026
@Fidget-Spinner
Fidget-Spinner dismissed markshannon’s stale review March 22, 2026 16:56

Mark's review has already been addressed and given 2 weeks for a response.

@Fidget-Spinner
Fidget-Spinner merged commit e36f8db into python:main Mar 22, 2026
87 of 88 checks passed

Uh oh!

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

@bedevere-app bedevere-app Bot removed the awaiting merge label Mar 22, 2026
@eendebakpt eendebakpt mentioned this pull request Mar 22, 2026
Optimize float operations by mutating uniquely-referenced operands in place (JIT only) #146306
Closed
CuriousLearner added a commit to CuriousLearner/cpython that referenced this pull request Mar 23, 2026
@CuriousLearner
Merge branch 'main' of github.com:python/cpython into fix-pythongh-13…
3e05fa3
…8577

* 'main' of github.com:python/cpython:
  pythongh-146197: Run -m test.pythoninfo on the Emscripten CI (python#146332)
  pythongh-146325: Use `test.support.requires_fork` in test_fastpath_cache_cleared_in_forked_child (python#146330)
  pythongh-146197: Add Emscripten to CI (python#146198)
  pythongh-143387: Raise an exception instead of returning None when metadata file is missing. (python#146234)
  pythongh-108907: ctypes: Document _type_ codes (pythonGH-145837)
  pythongh-146175: Soft-deprecate outdated macros; convert internal usage (pythonGH-146178)
  pythongh-146056: Rework ref counting in treebuilder_handle_end() (python#146167)
  Add a warning about untrusted input to `configparser` docs (python#146276)
  pythongh-145264: Do not ignore excess Base64 data after the first padded quad (pythonGH-145267)
  pythongh-146308: Fix error handling issues in _remote_debugging module (python#146309)
  pythongh-146192: Add base32 support to binascii (pythonGH-146193)
  pythongh-135953: Properly obtain main thread identifier in Gecko Collector (python#146045)
  pythongh-143414: Implement unique reference tracking for JIT, optimize unpacking of such tuples (pythonGH-144300)
  pythongh-146261: Fix bug in `_Py_uop_sym_set_func_version` (pythonGH-146291)
  pythongh-145144: Add more tests for UserList, UserDict, etc (pythonGH-145145)
  pythongh-143959: Fix test_datetime if _datetime is unavailable (pythonGH-145248)
  pythongh-146245: Fix reference and buffer leaks via audit hook in socket module (pythonGH-146248)
  pythongh-140049: Colorize exception notes in `traceback.py` (python#140051)
  Update docs for pythongh-146056 (pythonGH-146213)
@eendebakpt

eendebakpt commented Apr 4, 2026

Copy link
Copy Markdown
Contributor

FYI: Adding unique reference tracking for lists is possible in a similar way as done for tuples in this PR. A prototype is main...eendebakpt:cpython:unique_list. Performance improves, but I am not sure unique list unpacking is as relevant as tuple unpackage @Fidget-Spinner

All reactions

Sorry, something went wrong.

Uh oh!

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

@pablogsal pablogsal mentioned this pull request Apr 4, 2026
gh-130273: Fix traceback color output with unicode characters #142529
Merged
ljfp pushed a commit to ljfp/cpython that referenced this pull request Apr 25, 2026
@reidenong @Fidget-Spinner @ljfp
pythongh-143414: Implement unique reference tracking for JIT, optimiz…
8d05049
…e unpacking of such tuples (pythonGH-144300)

Co-authored-by: Ken Jin <[email protected]>
@reidenong
reidenong deleted the branch-unique-reference-tracking branch September 2, 2026 04:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@cocolato cocolato cocolato left review comments
@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
@markshannon markshannon Awaiting requested review from markshannon markshannon is a code owner

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.

5 participants

@reidenong @Fidget-Spinner @eendebakpt @markshannon @cocolato
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.