@Inada (senpai?): In the meanwhile I tried to apply some tricks to speedup the dict creation without success. This is my effort: https://github.com/Marco-Sulla/cpython/blob/master/Objects/dictobject.c
As you can see, I simply "cloned" some functions that create dict, and removed some checks that are not needed at creation: 1. the "override" flag 2. the check for resizing, since in theory I would do one big resize at start (but I have some problems, see below) 3. the introduction of an "empty" parameter, that is false only if you have to insert key-value pairs AND you also have a positional parameter 4. some random const, when the code permits it 5. changing of ma_used, ma_version_tag, dk_usable, dk_nentries only one time, after the for loop that insert all the items 6. some little shortcut (for example, PyDictKeysObject *keys = mp->ma_keys; and using keys in the rest of the code) 7. changing some checks in asserts 8. calling directly the internal static functions I tested it with a dict with an "hole", since I noticed that you already improved the creation of dict when the source it's another dict and it's "perfect". The speedup is a mere 2.5%... Furthermore, I failed to do one big resize with dict. I was ok with frozendict because I always used dicts or seq2 as parameters. But defaultdict passes a class as first argument. So PyObject_Length fails miserably, and I had to remove the resize. Anyway, I didn't reintroduce the resize, so in theory the code should be faster (even if one odict test fails, of course). Some questions: 1. How can we check the size of an object only if it's an iterable using the Python C API? 2. Why, in your opinion, no relevant speedup was done? PS: My next and final try is to improve the speed of lookups, the only other field where frozendict is faster. I hope to have better luck here. _______________________________________________ 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/CVJWH4CFUA3RDKDPY74LQXFKN6NZS4B5/ Code of Conduct: http://python.org/psf/codeofconduct/