[issue46845] dict: Use smaller entry for Unicode-key only dict.

2022-03-03 Thread Mark Shannon
Change by Mark Shannon : -- pull_requests: +29777 pull_request: https://github.com/python/cpython/pull/31659 ___ Python tracker ___

[issue46845] dict: Use smaller entry for Unicode-key only dict.

2022-03-01 Thread Inada Naoki
Change by Inada Naoki : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker ___ ___

[issue46845] dict: Use smaller entry for Unicode-key only dict.

2022-03-01 Thread Inada Naoki
Inada Naoki added the comment: New changeset 9833bb91e4d5c2606421d9ec2085f5c2dfb6f72c by Inada Naoki in branch 'main': bpo-46845: Reduce dict size when all keys are Unicode (GH-31564) https://github.com/python/cpython/commit/9833bb91e4d5c2606421d9ec2085f5c2dfb6f72c --

[issue46845] dict: Use smaller entry for Unicode-key only dict.

2022-02-26 Thread Inada Naoki
Inada Naoki added the comment: I added _PyDict_FromItems() to the PR. It checks that all keys are Unicode or not before creating dict. _PyDict_NewPresized() just returns general-purpose dict. But it isn't used from CPython core. It is just kept for compatibility (for Cython). ``` $ ./python

[issue46845] dict: Use smaller entry for Unicode-key only dict.

2022-02-26 Thread Inada Naoki
Inada Naoki added the comment: In most case, first PyDict_SetItem decides which format should be used. But _PyDict_NewPresized() can be a problem. It creates a hash table before inserting the first key, when 5 < (expected size) < 87382. In CPython code base, _PyDict_NewPresized() is called

[issue46845] dict: Use smaller entry for Unicode-key only dict.

2022-02-25 Thread Inada Naoki
Inada Naoki added the comment: > > > Do you propose to > 1. Only use StringKeyDicts when non-string keys are not possible? (Where > would this be?) > 2. Switch to a normal dict when a non-string key is added? (But likely > not switch back when the last non-string key is removed.) > 3.

[issue46845] dict: Use smaller entry for Unicode-key only dict.

2022-02-25 Thread Terry J. Reedy
Terry J. Reedy added the comment: CPython, at least, allows users to insert non-string keys in namespace dicts that are conceptually string-key only. >>> globals()[0] = 'zero' >>> globals()[0] 'zero' >>> vars() {'__name__': '__main__', ..., 0: 'zero'} [This is for consenting adults only, as

[issue46845] dict: Use smaller entry for Unicode-key only dict.

2022-02-24 Thread Inada Naoki
Change by Inada Naoki : -- keywords: +patch pull_requests: +29686 stage: -> patch review pull_request: https://github.com/python/cpython/pull/31564 ___ Python tracker ___

[issue46845] dict: Use smaller entry for Unicode-key only dict.

2022-02-23 Thread Inada Naoki
New submission from Inada Naoki : Currently, PyDictKeyEntry is 24bytes (hash, key, and value). We can drop the hash from entry when all keys are unicode, because unicode objects caches hash already. This will cause some performance regression on microbenchmark because dict need one more