-
-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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
Use per-thread freelists in --disable-gil
builds
#111968
Comments
Hi! |
Got it, thanks. |
I don't think there are any good issues right now that are scoped out and not blocked on other work. |
Okay, got it. Thank you |
@colesbury I would like to take a look at this issue, Is there any pending issues that are related to this issue? |
@corona10, thanks! I think the issues were fixed (problems with |
#113584 will introduce seamless management of freelists that runtimes do not need to care about the implementation detail :) graph TD;
PerThread --> FreeList;
PerInterpreter --> FreeList;
GC -- if free-threaded --> gc_freethreading;
GC -- if default build --> gc_gil;
gc_freethreading --> PerThread;
gc_gil --> PerInterpreter;
_PyFreeListState -- if free-threaded --> PerThread;
_PyFreeListState -- if default build --> PerInterpreter;
Runtime -- _PyFreeListState_GET --> _PyFreeListState;
list --> Runtime;
tuple --> Runtime;
slice --> Runtime;
float --> Runtime;
dict --> Runtime;
generator --> Runtime;
PyContext --> Runtime;
|
Final diagram: graph TD;
PerThread --> FreeList;
PerInterpreter --> FreeList;
GC -- if free-threaded --> gc_freethreading;
GC -- if default build --> gc_gil;
gc_freethreading --> PerThread;
gc_gil --> PerInterpreter;
_Py_object_freelists -- if free-threaded --> PerThread;
_Py_object_freelists -- if default build --> PerInterpreter;
Runtime -- _Py_object_freelists_GET --> _Py_object_freelists;
list --> Runtime;
tuple --> Runtime;
slice --> Runtime;
float --> Runtime;
dict --> Runtime;
dictkey --> Runtime;
async_gen --> Runtime;
_PyContext --> Runtime;
object_stack --> Runtime;
|
(from #111968 (comment))
Thanks for taking care of these, @corona10! FWIW, there are definitely a bunch of things we could do to simplify our use of freelists and make our implementation more maintainable, but all that mostly pre-dates this issue and is certainly something to be considered separately from this issue. 😄 |
@ericsnowcurrently @colesbury |
Feature or enhancement
CPython uses freelists for frequently allocated Python objects, like
dict
,list
, andslice
. There freelists are generally stored in the per-interpreter state, which is not thread-safe without the GIL. In--disable-gil
builds, the freelists should be stored in the per-thread state (i.e.,PyThreadState
). I think we probably want to keep the freelists in the interpreter state for the default build. This will probably require some refactoring.Freelists:
float
slice
(slice_cache
)tuple
list
dict
(PyDictKeysObject
andPyDictObject
)generator
(value_freelist
andasend_freelist
)PyContext
For context, here are similar changes in the
nogil-3.12
fork, but I expect the changes in CPython 3.13 to be a bit different:Linked PRs
The text was updated successfully, but these errors were encountered: