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 serhiy.storchaka
Recipients rhettinger, serhiy.storchaka
Date 2019-09-18.20:46:08
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1568839568.62.0.894949186749.issue38219@roundup.psfhosted.org>
In-reply-to
Content
dict.__init__() and dict.update() with a positional argument look up the "keys" attribute of the argument to distinguish a mapping from a sequence of item-value pairs. It has a non-trivial cost. Merging dicts is optimized for exact dicts in PyDict_Merge(), so it would be worth to optimize also this check.

$ ./python -m pyperf timeit -s "d = {}; D = dict" -- "D(d)"
Unpatched:  Mean +- std dev: 154 ns +- 4 ns
Patched:    Mean +- std dev: 110 ns +- 4 ns

$ ./python -m pyperf timeit -s "d = {}" -- "d.update(d)"
Unpatched:  Mean +- std dev: 112 ns +- 3 ns
Patched:    Mean +- std dev: 70.4 ns +- 1.5 ns

The cost of the check is about 40 ns, and it is a significant part of the total time of creating/updating a small dict.
History
Date User Action Args
2019-09-18 20:46:08serhiy.storchakasetrecipients: + serhiy.storchaka, rhettinger
2019-09-18 20:46:08serhiy.storchakasetmessageid: <1568839568.62.0.894949186749.issue38219@roundup.psfhosted.org>
2019-09-18 20:46:08serhiy.storchakalinkissue38219 messages
2019-09-18 20:46:08serhiy.storchakacreate