[Python-Dev] py2.7: dictobject not properly resizing (original) (raw)

Armin Rigo arigo at tunes.org
Sat Mar 30 22:56:10 CET 2013


Hi Antoine,

On Sat, Mar 30, 2013 at 10:37 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:

On Sat, 30 Mar 2013 17:31:26 -0400 Micha Gorelick <mynameisfiber at gmail.com> wrote:

I was taking a look at dictobject.c and realized that the logic controlling whether a resizedict will occur in dictsetitembyhashorentry disallows for the shrinking of a dictionary.

It doesn't disallow shrinking. If you take a dictionary of size 1000, remove of its elements, and continue to use it (write and delete more items) for long enough, then eventually it is shrinked. It just takes a while because it needs to fill 2/3 of the slots of the big table with "deleted" markers before it happens.

Python 3.3.0b1 (default:07ddf5ecaafa, Aug 12 2012, 17:47:28) [GCC 3.4.6 (Gentoo 3.4.6-r2, ssp-3.4.6-1.0, pie-8.7.10)] on linux Type "help", "copyright", "credits" or "license" for more information.

d = {i:i for i in range(1000)} sys.getsizeof(d) 24624 for i in range(1000): del d[i] ... sys.getsizeof(d) 24624 for j in range(1001, 2000): ... d[j] = 0; del d[j] ... sys.getsizeof(d) 144

A bientôt,

Armin.



More information about the Python-Dev mailing list