This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author josh.r
Recipients josh.r, lebedov, pitrou, rhettinger, serhiy.storchaka, vstinner
Date 2014-05-15.02:08:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1400119701.62.0.579289347615.issue21507@psf.upfronthosting.co.za>
In-reply-to
Content
I think the argument against using PyObject_LengthHint for the general iterable case is that for inputs other than sets or dicts, the assumption is that significant deduplication will occur. With your patch, if I run:

myset = frozenset([0] * 1000000)

it will allocate space for, if I'm reading it correctly, two million entries, and use exactly one of them. Obviously not the common case, but preallocating when you have no idea how much duplication will occur seems like a bad idea.

With a set or dict, you know it's already deduplicated, so preallocation is always a good thing, but for the general case, you'll be using more memory than necessary much of the time.
History
Date User Action Args
2014-05-15 02:08:21josh.rsetrecipients: + josh.r, rhettinger, pitrou, vstinner, serhiy.storchaka, lebedov
2014-05-15 02:08:21josh.rsetmessageid: <1400119701.62.0.579289347615.issue21507@psf.upfronthosting.co.za>
2014-05-15 02:08:21josh.rlinkissue21507 messages
2014-05-15 02:08:20josh.rcreate