| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Sorry, something went wrong.
| PyObject *op = FROM_GC(gc); | ||
| traverse = Py_TYPE(op)->tp_traverse; | ||
| PyTypeObject *type = Py_TYPE(op); | ||
| legacy_finalizer_count += type->tp_del != NULL; |
There was a problem hiding this comment.
This checks tp_del on every mortal candidate to avoid scanning the objects that end up as garbage. Even a live object with tp_del prevents the skip.
The reachability walk seems a better place to gather this. In a related change I made in an earlier PR, survivor counting was folded into that walk. We could use the same placement here and set a boolean when an object enters the provisional garbage list. If it gets rescued later, we just do the scan unnecessarily.
That removes this bookkeeping from the reference walkers. The exact count is unneeded anyway since we only need to know whether any legacy finalizers are present. This alternative still needs building and measuring.
Sorry, something went wrong.
Count the stable unreachable set while preparing callbacks and retain a conservative cleanup flag. Reuse the count only when late weakref clearing has no work, and force fresh cleanup and counting after resurrection analysis. Add a regression for a callback-free weakref observed when clearing a young cycle releases an older finalizer.
Count tp_del candidates during the existing reference traversals so zero can skip legacy classification. Reuse callback preparation to clear initial unreachable tags, while preserving normalized links before DEBUG_COLLECTABLE output can invoke Python. Cover debug visibility of weakrefs with callbacks and legacy classification during a generation 0 collection.
| Back | FazBrowse Home | New Git URL |
With this optimization the GIL collector counts mortal candidates whose type defines tp_del during the existing reference passes. A zero count rules out legacy finalizers in the garbage, so the collector skips their classification and reachability scans. On that path, it also clears unreachable tags during weakref preparation. With DEBUG_COLLECTABLE, the tags are cleared earlier, before debug output can run Python.
Performance
Before is #159599 (9fe33d48); after is this PR at c3d13211. Both builds use -falign-functions=64.
gc_collect_large uses 10,000 independent cycles containing 210,000 garbage objects.
Benchmarks: python/pyperformance#496