Open
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagetype-featureA feature request or enhancement
Description
Current layout
Currently the _dictkeysobject struct is laid out like this:
ptr ----> +--------------+
| header |
+--------------+
| indices |
+--------------+
| keys |
+--------------+
which requires some relatively expensive calculation to find the start of the keys, as the indices are not only variable in number, but variable in size also.
Proposed layout
If instead it is laid out as follows:
+--------------+
| indices |
ptr ----> +--------------+
| header |
+--------------+
| keys |
+--------------+
and the indices laid from highest to lowest with 0 just before ptr, finding the start of the keys is as simple as ptr->keys . Accessing an index is no slower, and the code barely any more complex.
Linked PRs
Reacted by Gregory P. Smith
Reacted by stonebig and Carlos Sousa
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagetype-featureA feature request or enhancement
Activity
rhettinger commentedon Dec 17, 2025
This seems like a reasonable experiment.