Turn off cycle detection at runtime?

"Martin v. Löwis" martin at v.loewis.de
Sun Dec 29 11:44:26 EST 2002


François Pinard wrote:
>>If I don't create cycles in my data, I can disable "gc" without anything
>>bad happening.
> 
> One gains execution speed, even quite notably in some applications.

In many applications, there will be no difference in execution speed at 
all, though. gc.disable does exactly that: the garbage collector won't 
run. Objects are still tracked in global lists, which gives a constant 
per-object overhead on object allocation and deallocation.

Even under normal circumstances, the collector will be invoked rarely: 
every 1000 new objects, a generation 1 collection is initiated. In an 
application that does not create cycles, many objects will die before gc 
is invoked, so they don't count towards the 1000 objects.

To gain notable execution speed by disabling the gc, you have to create 
many non-cyclic objects (say, by creating a deep tree or a long list), 
so that gc is invoked a number of times on creation of that structure. 
Since a generation 1 collection is relatively fast, and a generation 2 
collection happens only every 10000 new objects, you really need to 
consume a significant amount of memory to notice an effect from not 
doing garbage collection.

Regards,
Martin




More information about the Python-list mailing list