https://github.com/python/cpython/commit/37c31bea72fb6971f1008faa2e253d12167c221f
commit: 37c31bea72fb6971f1008faa2e253d12167c221f
branch: main
author: Sam Gross <[email protected]>
committer: colesbury <[email protected]>
date: 2024-05-03T18:16:45-04:00
summary:

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.

files:
M Objects/codeobject.c

diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index 7d02b038cf52ca..15d3960fc2df51 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;

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to