[New-bugs-announce] [issue29019] dict.fromkeys overallocates when given a sparse dict

Rasmus Villemoes report at bugs.python.org
Mon Dec 19 18:29:42 EST 2016


New submission from Rasmus Villemoes:

Somewhat related to #23971, but with the opposite sign: Using Py_SIZE on a PyDictObject gives the ma_fill member in 2.7 (and until 3.2 AFAICT), not the ma_used member. So calling dict.fromkeys(d) overallocates significantly if a lot of elements have been deleted from d.

The fix is trivial, though one could of course avoid the function call and do a cast. Not sure this qualifies for 2.7, though.

----------
components: Interpreter Core
files: fromkeys.patch
keywords: patch
messages: 283654
nosy: villemoes
priority: normal
severity: normal
status: open
title: dict.fromkeys overallocates when given a sparse dict
type: resource usage
versions: Python 2.7
Added file: http://bugs.python.org/file45973/fromkeys.patch

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


More information about the New-bugs-announce mailing list