Performance with and without the garbage collector

Paul Rubin no.email at nospam.invalid
Sat May 14 14:41:55 EDT 2016


Steven D'Aprano <steve at pearwood.info> writes:
> Is anyone able to demonstrate a replicable performance impact due to
> garbage collection?

As Laurent describes, Python uses refcounting, and then does some gc in
case there was dead circular structure that the refcounting missed.
Your example had no circular structure so there was nothing to gc, and
after refcounting freed the contents of your big array, there was hardly
anything for the gc to even inspect.

A standard example where you want gc is something like an XML DOM: a big
tree of nodes where the parents point to the children and the children
point back to the parents, so there are cyclic references all over the
place.  This can also be handled semi-manually with weakrefs and it's
sometimes done that way in gc'd systems to improve performance, but gc
is the fully automatic way to deal with it.



More information about the Python-list mailing list