python / cpython

The Python programming language
https://www.python.org
Other
63.58k stars 30.46k forks source link

Clear per-thread free-list concurrently from GC #114016

Open corona10 opened 10 months ago

corona10 commented 10 months ago

From https://github.com/python/cpython/issues/111968, we now manage free lists as per-thread resources. But the overhead of this implementation is that gc should traverse the resources of all threads that belong to the interpreter.

Since the clearing multiple per thread resources can be split by multiple thread tasks, it will be beneficial to reduce GC time.

ref: https://github.com/python/cpython/pull/113584#discussion_r1438822073 source code: https://github.com/python/cpython/blob/dac1da21218a406652b35919aa2118cc32d4c65a/Python/gc_free_threading.c#L21-L27

cc @colesbury

rruuaanng commented 1 month ago

I have submitted the best solution for this problem and also improved the interpreter's lock management for this operation.