-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-118527: Intern code consts in free-threaded build #118667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
We already intern and immortalize most string constants. In the free-threaded build, other constants can be a source of reference count contention because they are shared by all threads running the same code objects.
!buildbot nogil |
🤖 New build scheduled with the buildbot fleet by @colesbury for commit 5e8c0f0 🤖 The command will test the builders whose names match following regular expression: The builders matched are:
|
else if (PyTuple_CheckExact(op)) { | ||
Py_ssize_t size = PyTuple_GET_SIZE(op); | ||
PyObject **data = _PyTuple_ITEMS(op); | ||
return _Py_HashBytes(data, sizeof(PyObject *) * size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We first intern and de-dupe the contents so identity comparisons (including hasing pointers) is sufficient.
For example the following prints True
with this PR:
def foo():
return (0.0, (1, 2, "hello"))
def bar():
return (0.0, (1, 2, "hello"))
print(foo() is bar())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding the mutex to LOCKS_INIT
is really the most important thing, the slices are probably fine either way, it'd just be a little less duplication if we followed them, but they're probably usually in the small ints list anyway.
!buildbot nogil |
🤖 New build scheduled with the buildbot fleet by @colesbury for commit f5cab78 🤖 The command will test the builders whose names match following regular expression: The builders matched are:
|
…8667) We already intern and immortalize most string constants. In the free-threaded build, other constants can be a source of reference count contention because they are shared by all threads running the same code objects.
We already intern and immortalize most string constants. In the free-threaded build, other constants are a frequent source of reference count contention because they are shared by all threads running the same code objects.
For example, the following function would not otherwise scale because
1.5
would be a non-immortalized constant shared by all threads that executerun_in_parallel
.