
I've done a PR: https://github.com/python/cpython/pull/22346
As you can see, changes are not dramatical, if you improve only kw creation. Furthermore, IMHO insert_to_emptydict() can be removed, since it speeds up the insertion of the first element, but slows down all the others. I do something similar in insertdict_init, but in "bulk mode".
On Thu, 17 Sep 2020 at 16:49, Marco Sulla Marco.Sulla.Python@gmail.com wrote:
On Thu, 17 Sep 2020 at 05:31, Inada Naoki songofacandy@gmail.com wrote:
On Thu, Sep 17, 2020 at 8:03 AM Marco Sulla Marco.Sulla.Python@gmail.com wrote:
python -m timeit -n 2000 --setup "from uuid import uuid4 ; o = {str(uuid4()).replace('-', '') : str(uuid4()).replace('-', '') for i in range(10000)}" "dict(**o)"
I don't think this use case is worth to optimize, because `dict(o)` or `o.copy()` is Pythonic.
Well, also {**dict1, **dict2} is pythonic. Anyway, I used **dict as a shortcut for testing keyword assignment. For doing this I "only" cloned PyDict_SetItem and insertdict.
I do not like code duplication, but dictobject.c has already a lot of duplicated copies of the same function for optimization (see lookdict).