Populating a dictionary, fast

Hrvoje Niksic hniksic at xemacs.org
Mon Nov 12 05:37:42 EST 2007


Paul Rubin <http://phr.cx@NOSPAM.invalid> writes:

> Michael Bacarella <mbac at gpshopper.com> writes:
>> If only it were so easy.
>
> I think I know what's going on, the dictionary updates are sending the
> GC into quadratic behavior.  Try turning off the GC:
>
>     import gc
>     gc.disable()

This is becoming an FAQ on this newsgroup, having come up first with
lists and now with dictionaries.  It can also be considered a serious
implementation problem, since code like Michael's is expected to
perform in (close to) linear time and in fact did so in previous
versions of Python, and still does in Perl and other popular scripting
languages.  Neither introductory nor intermediate Python learning
materials don't cover the need to disable GC when building large data
structures.

Maybe the default GC strategy should be rethought.



More information about the Python-list mailing list