Title: Populate the initial per-interpreter interned_strings dict with runtime-global singleton strings · Issue #103571 · python/cpython · GitHub
Open Graph Title: Populate the initial per-interpreter interned_strings dict with runtime-global singleton strings · Issue #103571 · python/cpython
X Title: Populate the initial per-interpreter interned_strings dict with runtime-global singleton strings · Issue #103571 · python/cpython
Description: Feature or enhancement Re-use the runtime-global singleton strings inside the interned_strings dict to reduce duplication of singleton strings (improving performance where such strings are used). Pitch bpo-46430 (#30683) caused an intere...
Open Graph Description: Feature or enhancement Re-use the runtime-global singleton strings inside the interned_strings dict to reduce duplication of singleton strings (improving performance where such strings are used). P...
X Description: Feature or enhancement Re-use the runtime-global singleton strings inside the interned_strings dict to reduce duplication of singleton strings (improving performance where such strings are used). P...
Opengraph URL: https://github.com/python/cpython/issues/103571
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Populate the initial per-interpreter interned_strings dict with runtime-global singleton strings","articleBody":"# Feature or enhancement\r\n\r\nRe-use the runtime-global singleton strings inside the interned_strings dict to reduce duplication of\r\nsingleton strings (improving performance where such strings are used).\r\n\r\n# Pitch\r\n\r\nbpo-46430 (https://github.com/python/cpython/pull/30683) caused an interesting side effect; the code\r\n`x = 'a'; x[0] is x` no longer returned True. This in turn\r\nis because there are two different cached versions of 'a':\r\n\r\n- One that was cached when code in frozen modules was compiled\r\n (and is stored in the interned_dict)\r\n- One that is stored as a runtime-global object that is used\r\n during function calls (and is stored in _Py_SINGLETON(strings))\r\n\r\nHowever, some characters do not have this behaviour (for example,\r\n'g', 'u', and 'z'). I suspect it because these characters are not\r\nused in co_consts of frozen modules.\r\n\r\nThe interned_dict is per interpreter, and is initialized by\r\n`init_interned_dict(PyInterpreterState *)`. Currently, it is\r\ninitialized to an empty dict, which allows code in frozen modules\r\nto use their (different and per interpreter) singleton strings\r\ninstead of the runtime-global one.\r\n\r\nUsing the synthetic test case:\r\n\r\n```python\r\ndef test():\r\n total = 0\r\n for ch in 'abc':\r\n if ch in {'a', 'c'}:\r\n total += 1\r\n return total\r\n\r\ntimeit.timeit(`test()`, globals=globals())\r\n```\r\n\r\nI get a ~5.43% improvement when the interned_strings dict reuses the runtime-global singleton strings.\r\n# Previous discussion\r\n\r\n\u003c!--\r\n New features to Python should first be discussed elsewhere before creating issues on GitHub,\r\n for example in the \"ideas\" category (https://discuss.python.org/c/ideas/6) of discuss.python.org,\r\n or the python-ideas mailing list (https://mail.python.org/mailman3/lists/python-ideas.python.org/).\r\n Use this space to post links to the places where you have already discussed this feature proposal:\r\n--\u003e\r\n\r\n\r\n\u003c!--\r\nYou can freely edit this text. Remove any lines you believe are unnecessary.\r\n--\u003e\r\n\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-103572\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/Christopher-Chianelli","@type":"Person","name":"Christopher-Chianelli"},"datePublished":"2023-04-16T00:56:28.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/103571/cpython/issues/103571"}
| 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:e94aa28b-bbdb-31a2-5747-230bddef2cf5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8C2C:1A5CCB:2D2F5C:3FA665:696A42D8 |
| html-safe-nonce | 3ad525a7c3d5f10dd84888ff06b491cab70bcc11775e5d3daa679232b0535c7f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QzJDOjFBNUNDQjoyRDJGNUM6M0ZBNjY1OjY5NkE0MkQ4IiwidmlzaXRvcl9pZCI6IjgxNDY0MTMzNDg1NDMxNTI4NTYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | cde421b260e195b93dff3faa8393d2a10b3a1726abf718185ad6f022e38a6ef2 |
| hovercard-subject-tag | issue:1669624723 |
| 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/103571/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5f81fa3153e5e4e3e371f185810b7d7f4787c72ccbb3bf5336043f33e9fe2566/python/cpython/issues/103571 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5f81fa3153e5e4e3e371f185810b7d7f4787c72ccbb3bf5336043f33e9fe2566/python/cpython/issues/103571 |
| og:image:alt | Feature or enhancement Re-use the runtime-global singleton strings inside the interned_strings dict to reduce duplication of singleton strings (improving performance where such strings are used). P... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Christopher-Chianelli |
| hostname | github.com |
| expected-hostname | github.com |
| None | 3f871c8e07f0ae1886fa8dac284166d28b09ad5bada6476fc10b674e489788ef |
| 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 | 63c426b30d262aba269ef14c40e3c817b384cd61 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width