Message352753
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. |
|
Date |
User |
Action |
Args |
2019-09-18 20:46:08 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, rhettinger |
2019-09-18 20:46:08 | serhiy.storchaka | set | messageid: <1568839568.62.0.894949186749.issue38219@roundup.psfhosted.org> |
2019-09-18 20:46:08 | serhiy.storchaka | link | issue38219 messages |
2019-09-18 20:46:08 | serhiy.storchaka | create | |
|