summaryrefslogtreecommitdiffstats
path: root/Objects/codeobject.c
diff options
context:
space:
mode:
authorSam Gross <colesbury@gmail.com>2024-05-03 22:16:45 (GMT)
committerGitHub <noreply@github.com>2024-05-03 22:16:45 (GMT)
commit37c31bea72fb6971f1008faa2e253d12167c221f (patch)
tree7f45a8a0bc9f7bd77b1fa8423523e9f4f24e6cde /Objects/codeobject.c
parent0e78a545e6e78b16eb7709ec3db2243364603134 (diff)
downloadcpython-37c31bea72fb6971f1008faa2e253d12167c221f.zip
cpython-37c31bea72fb6971f1008faa2e253d12167c221f.tar.gz
cpython-37c31bea72fb6971f1008faa2e253d12167c221f.tar.bz2
gh-118527: Intern filename, name, and qualname in code objects. (#118558)
This interns the strings for `co_filename`, `co_name`, and `co_qualname` on codeobjects in the free-threaded build. This partially addresses a reference counting bottleneck when creating closures concurrently. The closures take the name and qualified name from the code object.
Diffstat (limited to 'Objects/codeobject.c')
-rw-r--r--Objects/codeobject.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index 7d02b03..15d3960 100644
--- a/Objects/codeobject.c
+++ b/Objects/codeobject.c
@@ -390,6 +390,11 @@ init_code(PyCodeObject *co, struct _PyCodeConstructor *con)
co->co_filename = Py_NewRef(con->filename);
co->co_name = Py_NewRef(con->name);
co->co_qualname = Py_NewRef(con->qualname);
+#ifdef Py_GIL_DISABLED
+ PyUnicode_InternInPlace(&co->co_filename);
+ PyUnicode_InternInPlace(&co->co_name);
+ PyUnicode_InternInPlace(&co->co_qualname);
+#endif
co->co_flags = con->flags;
co->co_firstlineno = con->firstlineno;