[issue4688] GC optimization: don't track simple tuples and dicts

Martin v. Löwis report at bugs.python.org
Thu Dec 18 07:43:47 CET 2008


Martin v. Löwis <martin at v.loewis.de> added the comment:

> Unfortunately, the check is O(n), so it can get a little expensive.

Not in the typical case, I guess. *If* you have to go through all
objects, then likely you end up untracking the object. If you can't
untrack, you typically find a tracked object in the content quickly.

> I suppose that's no worse than traversing the tuple to look for a cycle,
> though.  

Correct. Collection is O(n) per object, anyway.

> Perhaps it could be done at the same time?
> Can _PyObject_GC_UNTRACK() be safely called from tp_traverse?

No. However, I doubt that iterating over the object twice is
significantly slower than iterating over it once and performing
both checks. Plus, the check for tracked elements can return
as soon as one such object is found.

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4688>
_______________________________________


More information about the Python-bugs-list mailing list