Repository navigation
gh-159437: Skip tuple traversal when a tuple can be untracked - #159584
mfalco-oai wants to merge 1 commit into
Conversation
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
788521e to
9a79b53
Compare
| 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); |
There was a problem hiding this comment.
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.
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.