You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Populate the initial per-interpreter interned_strings dict with runtime-global singleton strings #103571
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 interesting side effect; the code x = 'a'; x[0] is x no longer returned True. This in turn
is because there are two different cached versions of 'a':
One that was cached when code in frozen modules was compiled
(and is stored in the interned_dict)
One that is stored as a runtime-global object that is used
during function calls (and is stored in _Py_SINGLETON(strings))
However, some characters do not have this behaviour (for example,
'g', 'u', and 'z'). I suspect it because these characters are not
used in co_consts of frozen modules.
The interned_dict is per interpreter, and is initialized by init_interned_dict(PyInterpreterState *). Currently, it is
initialized to an empty dict, which allows code in frozen modules
to use their (different and per interpreter) singleton strings
instead of the runtime-global one.
x = 'a'; x[0] is x is True in 3.10, False in 3.11. Neither is correct as the reference declares caching-dependent behaviors like this to be implementation details.
It is an implementation detail, it will soon change as that dict will be made immortal and be global instead of per-interpreter so it will be automatically be resolved, closing as it is not actionable for now.
Activity
terryjreedy commentedon Apr 16, 2023
x = 'a'; x[0] is xis True in 3.10, False in 3.11. Neither is correct as the reference declares caching-dependent behaviors like this to be implementation details.kumaraditya303 commentedon Apr 16, 2023
It is an implementation detail, it will soon change as that dict will be made immortal and be global instead of per-interpreter so it will be automatically be resolved, closing as it is not actionable for now.