[issue21507] set and frozenset constructor should use operator.length_hint to guess the size of the iterator

Josh Rosenberg report at bugs.python.org
Fri May 16 03:01:30 CEST 2014


Josh Rosenberg added the comment:

Not sure how much that really helps. If I understand you correctly, it would be a memory optimization that would require a round of rehashing to use?

If you wanted to make a change that got "guaranteed" better performance, you might add support for dict's dict_keys and dict_items objects (since those have the same uniqueness guarantees as a set or dict, and I could easily see someone creating sets from them to remove the link to the original dict).

If you wanted to get crazy, you might add preallocation support for collections.abc abstract classes equivalent to the built-ins, specifically, Set, Mapping, KeysView and ItemsView. That's probably not a good idea though, since it ends up calling out to Python code more (slowing you down for the general case) and it's probably not as safe, since a user-defined implementation of those abstract classes might not strictly adhere to the same uniqueness or hashability contracts the built-ins provide.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21507>
_______________________________________


More information about the Python-bugs-list mailing list