Skip to content

Commit 37c31be

Browse files
authored
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.
1 parent 0e78a54 commit 37c31be

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Diff for: Objects/codeobject.c

+5
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,11 @@ init_code(PyCodeObject *co, struct _PyCodeConstructor *con)
390390
co->co_filename = Py_NewRef(con->filename);
391391
co->co_name = Py_NewRef(con->name);
392392
co->co_qualname = Py_NewRef(con->qualname);
393+
#ifdef Py_GIL_DISABLED
394+
PyUnicode_InternInPlace(&co->co_filename);
395+
PyUnicode_InternInPlace(&co->co_name);
396+
PyUnicode_InternInPlace(&co->co_qualname);
397+
#endif
393398
co->co_flags = con->flags;
394399

395400
co->co_firstlineno = con->firstlineno;

0 commit comments

Comments
 (0)