On Sun, Jul 26, 2020 at 4:44 AM Marco Sulla <marco.sulla.pyt...@gmail.com> wrote: > > I also remembered another possible use-case: kwargs in CPython. In C code, > kwargs are PyDictObjects. I suppose they are usually not modified; if so, > fdict could be used, since it seems to be faster at creation. >
I have not confirmed why frozendict is faster than dict for creation. But note that kwargs is not created by `dict(d)`. It is created by PyDict_New() and PyDict_SetItem(). Please benchmark these C APIs if you want to propose the idea. https://github.com/python/cpython/blob/a74eea238f5baba15797e2e8b570d153bc8690a7/Python/ceval.c#L4155 https://github.com/python/cpython/blob/a74eea238f5baba15797e2e8b570d153bc8690a7/Python/ceval.c#L4245 FWIW, I optimized dict(d) in https://bugs.python.org/issue41431 (https://github.com/python/cpython/pull/21674 ) $ ./python -m pyperf timeit --compare-to ./python-master -s 'd=dict.fromkeys(range(1000))' -- 'dict(d)' python-master: ..................... 21.5 us +- 0.2 us python: ..................... 4.52 us +- 0.16 us Mean +- std dev: [python-master] 21.5 us +- 0.2 us -> [python] 4.52 us +- 0.16 us: 4.76x faster (-79%) Regards, -- Inada Naoki <songofaca...@gmail.com> _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/J6OOBGCTLEUX7CBDIDNKYPH4KNAZV4GQ/ Code of Conduct: http://python.org/psf/codeofconduct/