Message78001
Le mercredi 17 décembre 2008 à 23:56 +0000, Daniel Stutzbach a écrit :
> For tuples, I think the rule is:
> If an object is immutable, and it points only to untracked objects,
> the object can be untracked.
Roughly, yes. Exactly, it is "if it points only to untrackable objects".
That is, a tuple containing an untracked dict will still be tracked,
because the dict may mutate and become tracked later. But a tuple
containing an untracked tuple will itself be untracked, because the
enclosed tuple can't mutate.
> Is that right? If so, you could perform the same optimization on the
> frozenset() type.
Yes, but I prefer to concentrate on those two core types now, which are
the most frequent. Once the principle is accepted we can extend the
implementation to other types.
> Why do empty tuples have to be tracked?
Actually, they are never tracked, which means calling
_PyObject_GC_UNTRACK on them would segfault.
> The dict patch adds a boolean flag to the dict data structure to
> indicate whether the dict is being tracked or not. I think. Couldn't
> you use _PyObject_GC_IS_TRACKED() instead?
Yes, probably. I thought a dedicated flag may be faster but I will try
without.
> Do you
> need to recheck the rule every time the dict is modified?
Only if it is not tracked. Once a dict is tracked, it cannot become
untracked again (there would be too much overhead, and the assumption is
that you usually create homogeneous containers, you don't create a dict
of mutable containers things and then replace the mutable containers
with simple atomic objects). |
|
Date |
User |
Action |
Args |
2008-12-18 00:04:56 | pitrou | set | recipients:
+ pitrou, loewis, stutzbach |
2008-12-18 00:04:55 | pitrou | link | issue4688 messages |
2008-12-18 00:04:55 | pitrou | create | |
|