Title: General optimisations for dict lookup/insert performance · Issue #145179 · python/cpython · GitHub
Open Graph Title: General optimisations for dict lookup/insert performance · Issue #145179 · python/cpython
X Title: General optimisations for dict lookup/insert performance · Issue #145179 · python/cpython
Description: Proposal: There's room for tiny refactorings in the Objects/dictobject.c that may allow speedups, for example via better CPU cache behavior, compiler hints, cheap checks & fast exits for common cases. In my guess-timation, they may bring...
Open Graph Description: Proposal: There's room for tiny refactorings in the Objects/dictobject.c that may allow speedups, for example via better CPU cache behavior, compiler hints, cheap checks & fast exits for common cas...
X Description: Proposal: There's room for tiny refactorings in the Objects/dictobject.c that may allow speedups, for example via better CPU cache behavior, compiler hints, cheap checks & fast exits for co...
Opengraph URL: https://github.com/python/cpython/issues/145179
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"General optimisations for dict lookup/insert performance","articleBody":"### Proposal:\n\nThere's room for tiny refactorings in the `Objects/dictobject.c` that may allow speedups, for example via better CPU cache behavior, compiler hints, cheap checks \u0026 fast exits for common cases. In my guess-timation, they may bring about upto 10% overall lookup/insert performance gains. That's more of an un-scientific intuition at best right now, but I'm laying some ideas out here:\n\n* `compare_unicode_unicode()`: can benefit from pointer-equality and branch prediction, and reducing unnecessary function calls\n\n* `compare_generic()`: can use early rejections on hash-mismatch, avoiding `RichCompareBool` calls\n\n* `unicodekeys_lookup_unicode()`: pointer-equality for the common case can precede `do_lookup` which today is invoked everytime for all cases\n\n* `find_empty_slot()`: early termination / separate path for first iteration can speed up insertions, especially for lightly-populated dicts\n\n* `build_indices_generic / build_indices_unicode ()`: breaking out the first-probe success case may speed up dict resize operations\n\nI welcome feedback on how to raise this proposal differently, but otherwise I'd like to work on these ideas and quantify them. I feel modern CPUs have deep pipelines and these optimizations may help us avoid some cache-thrashing. These changes are purely performance oriented and don't change functionality / API / ABI and should be thread-safe too.\n\n### Has this already been discussed elsewhere?\n\nThis is a minor feature, which does not need previous discussion elsewhere\n\n### Links to previous discussion of this feature:\n\n_No response_","author":{"url":"https://github.com/caje731","@type":"Person","name":"caje731"},"datePublished":"2026-02-24T14:04:16.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/145179/cpython/issues/145179"}
| 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:f13c8c65-0d5f-243b-f568-6236360b8179 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A4B2:D1AA1:317CA02:464B6BF:6A5124AA |
| html-safe-nonce | 2055b2dbba09ccab803424946973cea724c904064fa9cfa3a6f38ad86f1d7bb1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNEIyOkQxQUExOjMxN0NBMDI6NDY0QjZCRjo2QTUxMjRBQSIsInZpc2l0b3JfaWQiOiI1OTg4MTExMjEwNTE1NjA0NjUwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 61c15e20046f5390c22a36fa01527854bbde1360d7a4102305fe9ddd5e4a3e6e |
| hovercard-subject-tag | issue:3983908276 |
| 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/145179/issue_layout |
| twitter:image | https://opengraph.githubassets.com/18f19fbdc98b42b7fcca09b903476d1207581eb193c91ca07c43acff3f8bb0ef/python/cpython/issues/145179 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/18f19fbdc98b42b7fcca09b903476d1207581eb193c91ca07c43acff3f8bb0ef/python/cpython/issues/145179 |
| og:image:alt | Proposal: There's room for tiny refactorings in the Objects/dictobject.c that may allow speedups, for example via better CPU cache behavior, compiler hints, cheap checks & fast exits for common cas... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | caje731 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 689b683944b0d7f015d0e776452c970832fa81b82dc15284469b556ecced715b |
| 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 | 942b51ed3bd5feee3d5e2719f890a5fe286edbbb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width