Populate the initial per-interpreter interned_strings dict with runtime-global singleton strings #103571
Labels
interpreter-core
(Objects, Python, Grammar, and Parser dirs)
performance
Performance or resource usage
type-feature
A feature request or enhancement
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 interesting side effect; the code
x = 'a'; x[0] is x
no longer returned True. This in turnis because there are two different cached versions of 'a':
(and is stored in the interned_dict)
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 isinitialized 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.
Using the synthetic test case:
I get a ~5.43% improvement when the interned_strings dict reuses the runtime-global singleton strings.
Previous discussion
Linked PRs
The text was updated successfully, but these errors were encountered: