[issue31179] Speed-up dict.copy() up to 5.5 times.
Yury Selivanov
report at bugs.python.org
Fri Aug 11 10:48:01 EDT 2017
Yury Selivanov added the comment:
> I like idea.
> One worrying point is how to deal with dirty dict.
> How about do it only when ma_used == keys->dk_nentries?
I've added this check. See the updated PR.
> The PR changes the behavior. Currently the effect of copying is compacting the dict.
The check that INADA suggested enables compacting on copy, if it is needed.
> The PR adds over 50 lines of code for optimising not very often used feature.
I started to look into the problem because I need this for my upcoming PEP, so please don't dismiss this idea right away.
I also think that copying a dict isn't a "not very often used feature", it depends on your frame of references. In some applications you do copy dict a lot. 50 lines of code speeding up one of the core methods 5.5x is a fair price to pay.
> There are two obvious ways of copying, dict(d) and d.copy()
That can also be easily optimized, btw. I'll see if I can do that without impacting the performance of creating new dicts.
> The PR duplicates the low-level code, that increases maintainability cost.
FWIW, the PR doesn't duplicate any of the code. It provides a new implementation that is more efficient than the old approach.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue31179>
_______________________________________
More information about the Python-bugs-list
mailing list