Title: Improved performance and arguably simpler code for dictionaries by changing the keys layout · Issue #142889 · python/cpython · GitHub
Open Graph Title: Improved performance and arguably simpler code for dictionaries by changing the keys layout · Issue #142889 · python/cpython
X Title: Improved performance and arguably simpler code for dictionaries by changing the keys layout · Issue #142889 · python/cpython
Description: Current layout Currently the _dictkeysobject struct is laid out like this: ptr ----> +--------------+ | header | +--------------+ | indices | +--------------+ | keys | +--------------+ which requires some relatively expensive calculation...
Open Graph Description: Current layout Currently the _dictkeysobject struct is laid out like this: ptr ----> +--------------+ | header | +--------------+ | indices | +--------------+ | keys | +--------------+ which requir...
X Description: Current layout Currently the _dictkeysobject struct is laid out like this: ptr ----> +--------------+ | header | +--------------+ | indices | +--------------+ | keys | +--------------+ which req...
Opengraph URL: https://github.com/python/cpython/issues/142889
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Improved performance and arguably simpler code for dictionaries by changing the keys layout","articleBody":"### Current layout\n\nCurrently the `_dictkeysobject` struct is laid out like this:\n```\nptr ----\u003e +--------------+\n | header |\n +--------------+\n | indices |\n +--------------+\n | keys |\n +--------------+\n```\nwhich 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.\n\n### Proposed layout\nIf instead it is laid out as follows:\n```\n +--------------+\n | indices |\nptr ----\u003e +--------------+\n | header |\n +--------------+\n | keys |\n +--------------+\n```\nand the indices laid from highest to lowest with 0 just before `ptr`, finding the start of the keys is as simple as `ptr-\u003ekeys` . Accessing an index is no slower, and the code barely any more complex.\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-145097\n* gh-150640\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/markshannon","@type":"Person","name":"markshannon"},"datePublished":"2025-12-17T15:58:54.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/142889/cpython/issues/142889"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:82669215-c448-d0a0-40ab-5eea854105ce |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B22A:1C4F37:15E9FA4:1DC061F:6A508E79 |
| html-safe-nonce | 8a02ba8c0face8cdc8839f9505fc70a3e9e4753f2f49ed376df1a0cbb1a2823e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMjJBOjFDNEYzNzoxNUU5RkE0OjFEQzA2MUY6NkE1MDhFNzkiLCJ2aXNpdG9yX2lkIjoiMjQ3Njg0NzM0MDA0NjAyODQwOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | fbeda1d8cbb1ed3b850779c63682aa98fa6828786604f7da3d57f413fbd15111 |
| hovercard-subject-tag | issue:3739483405 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/142889/issue_layout |
| twitter:image | https://opengraph.githubassets.com/da252b3efff3d6e107ea360c6c3ad8557d401c85fa48e6b27cd97bc44501e22b/python/cpython/issues/142889 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/da252b3efff3d6e107ea360c6c3ad8557d401c85fa48e6b27cd97bc44501e22b/python/cpython/issues/142889 |
| og:image:alt | Current layout Currently the _dictkeysobject struct is laid out like this: ptr ----> +--------------+ | header | +--------------+ | indices | +--------------+ | keys | +--------------+ which requir... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | markshannon |
| hostname | github.com |
| expected-hostname | github.com |
| None | d6dc8294eb500fa36bbc57472d61fe87c522f9c3c1d64f70f4926f66a66a7efb |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7ac0ad2f2c7e4b9056617355fd9e33e22b0c8df9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width