Author serhiy.storchaka
Recipients haypo, inada.naoki, serhiy.storchaka, yselivanov
Date 2017-08-11.07:10:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1502435408.31.0.851761537774.issue31179@psf.upfronthosting.co.za>
In-reply-to
Content
The PR adds over 50 lines of code for optimising not very often used feature. There are two obvious ways of copying, dict(d) and d.copy(), the PR optimises just the latter one, and I'm not sure this is the most used way. The PR duplicates the low-level code, that increases maintainability cost.

The PR changes the behavior. Currently the effect of copying is compacting the dict.

>>> import sys
>>> sys.getsizeof(d)
41020
>>> sys.getsizeof(d.copy())
41020
>>> sys.getsizeof(dict(d))
41020
>>> for i in range(1000): del d[i]
... 
>>> sys.getsizeof(dict(d))
20544
>>> sys.getsizeof(d.copy())
20544
>>> sys.getsizeof(d)
41020
>>> import sys
>>> d = dict.fromkeys(range(2000))
>>> sys.getsizeof(d)
41020
>>> sys.getsizeof(d.copy())
41020
>>> d = dict.fromkeys(range(2000))
>>> for i in range(1999): del d[i]
... 
>>> sys.getsizeof(d)
41020
>>> sys.getsizeof(d.copy())
136

The PR preserves non compact layout in the copy.
History
Date User Action Args
2017-08-11 07:10:08serhiy.storchakasetrecipients: + serhiy.storchaka, haypo, inada.naoki, yselivanov
2017-08-11 07:10:08serhiy.storchakasetmessageid: <1502435408.31.0.851761537774.issue31179@psf.upfronthosting.co.za>
2017-08-11 07:10:08serhiy.storchakalinkissue31179 messages
2017-08-11 07:10:06serhiy.storchakacreate