Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bd46b5f

Browse files
committed
wip: untrack tuples in "mark alive" pass
Make sure we still do this optimization. There is also a unit test that checks for this.
1 parent 5f6ab4c commit bd46b5f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Python/gc_free_threading.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,16 @@ mark_alive_stack_push(PyObject *op, _PyObjectStack *stack)
460460
if (gc_is_alive(op)) {
461461
return 0; // already visited this object
462462
}
463+
if (!_PyObject_HasDeferredRefcount(op)) {
464+
// Untrack objects that can never create reference cycles. Currently
465+
// we only check for tuples containing only non-GC objects.
466+
if (PyTuple_CheckExact(op)) {
467+
_PyTuple_MaybeUntrack(op);
468+
if (!_PyObject_GC_IS_TRACKED(op)) {
469+
return 0;
470+
}
471+
}
472+
}
463473
gc_set_alive(op);
464474
if (_PyObjectStack_Push(stack, op) < 0) {
465475
_PyObjectStack_Clear(stack);

0 commit comments

Comments
 (0)