Repository navigation
gh-159437: Skip unnecessary GC finalizer scans - #159587
mfalco-oai wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
The callback refactor seems bigger than skipping this scan needs. There is a new helper with a long argument list and the caller now has to choose between different garbage lists.
A related change I made in an earlier PR already tracks whether Python may have run. I tried extending that flow by recording pending finalizers during the weakref scan. That was a much smaller change in gc.c and kept the existing callback handling.
Let's keep the existing callback and resurrection flow unless there is a separate application benefit from the larger refactor.
Let's see what @nascheme thinks about the callback refactor too.
| return len(text) | ||
|
|
||
| writer = Stderr() | ||
| gc.collect() |
There was a problem hiding this comment.
This fails on its own with -X lazy_imports=all. I tried it with and without the PR and hit the collected object count assertion in each case. Binding patch_stderr = unittest.mock.patch.object before the initial collection fixed the failure. We should do that before this cleanup and use the bound function below.
With this optimization the GIL collector records pending finalizers while preparing weakref callbacks. If neither finalizers nor callbacks are pending, it skips the finalizer scan. Callbacks and
DEBUG_COLLECTABLEkeep the full path because they can run Python.