Skip to content

gh-159437: Skip tuple traversal when a tuple can be untracked - #159584

Draft
mfalco-oai wants to merge 1 commit into
python:mainfrom
mfalco-oai:mfalco-oai/gh-159437-gc-tuple
Draft

mfalco-oai wants to merge 1 commit into
python:mainfrom
mfalco-oai:mfalco-oai/gh-159437-gc-tuple

Conversation

@mfalco-oai

@mfalco-oai mfalco-oai commented Oct 16, 2026 •

Copy link
Copy Markdown

With this optimization the GIL collector checks whether a surviving exact tuple can be untracked before calling tp_traverse. Such a tuple cannot lead to another tracked object, so we can unlink it and skip the traversal.

@python-cla-bot

python-cla-bot Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Oct 16, 2026

mfalco-oai commented Oct 16, 2026 •

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-16T21:42:23.945677Z 788521e Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 788521e04f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@mfalco-oai
mfalco-oai force-pushed the mfalco-oai/gh-159437-gc-tuple branch from 788521e to 9a79b53 Compare October 16, 2026 23:23
Comment thread Python/gc.c
if (PyTuple_CheckExact(op) && _PyTuple_CanUntrack(op)) {
// Ordinary untracking would overwrite the next node's gc_refs.
PyGC_Head *next = GC_NEXT(gc);
_PyGCHead_SET_NEXT(prev, next);

@pablogsal pablogsal Oct 17, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This repeats the flag clearing and heap_size update from _PyObject_GC_UNTRACK(). A similar tuple change I worked on in an earlier PR saved and restored the next node's gc_refs so it could use the existing helper.

Could we reuse that here after restoring this node's predecessor link? It adds header writes, so that cost needs checking before replacing the manual unlink.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants