mirror of
https://github.com/python/cpython.git
synced 2025-12-15 21:44:50 +00:00
bpo-39465: Fix _PyUnicode_FromId() for subinterpreters (GH-20058)
Make _PyUnicode_FromId() function compatible with subinterpreters. Each interpreter now has an array of identifier objects (interned strings decoded from UTF-8). * Add PyInterpreterState.unicode.identifiers: array of identifiers objects. * Add _PyRuntimeState.unicode_ids used to allocate unique indexes to _Py_Identifier. * Rewrite the _Py_Identifier structure. Microbenchmark on _PyUnicode_FromId(&PyId_a) with _Py_IDENTIFIER(a): [ref] 2.42 ns +- 0.00 ns -> [atomic] 3.39 ns +- 0.00 ns: 1.40x slower This change adds 1 ns per _PyUnicode_FromId() call in average.
This commit is contained in:
parent
f0853bcedf
commit
ba3d67c2fb
6 changed files with 102 additions and 37 deletions
|
|
@ -49,6 +49,11 @@ typedef struct _Py_AuditHookEntry {
|
|||
void *userData;
|
||||
} _Py_AuditHookEntry;
|
||||
|
||||
struct _Py_unicode_runtime_ids {
|
||||
PyThread_type_lock lock;
|
||||
Py_ssize_t next_index;
|
||||
};
|
||||
|
||||
/* Full Python runtime state */
|
||||
|
||||
typedef struct pyruntimestate {
|
||||
|
|
@ -106,6 +111,8 @@ typedef struct pyruntimestate {
|
|||
void *open_code_userdata;
|
||||
_Py_AuditHookEntry *audit_hook_head;
|
||||
|
||||
struct _Py_unicode_runtime_ids unicode_ids;
|
||||
|
||||
// XXX Consolidate globals found via the check-c-globals script.
|
||||
} _PyRuntimeState;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue