-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
Closed
Labels
Description
The test_weakref
test is one of the slowest tests when running in the free-threaded build.
The problem is the default period for the collect_in_thread()
function is too short (100 µs). This isn't too much of a problem for the default build because the GIL switch interval is 5 ms, which effectively makes the smaller period irrelevant.
With the free-threaded build, this the 100 µs period means that the test spends the majority of its time calling gc.collect()
nearly non-stop.
We should increase the period to 5 ms or so. On my machine, this decreases up the overall test_weakref
time from 1 minute to 8 seconds.
cpython/Lib/test/test_weakref.py
Lines 84 to 103 in d909519
@contextlib.contextmanager | |
def collect_in_thread(period=0.0001): | |
""" | |
Ensure GC collections happen in a different thread, at a high frequency. | |
""" | |
please_stop = False | |
def collect(): | |
while not please_stop: | |
time.sleep(period) | |
gc.collect() | |
with support.disable_gc(): | |
t = threading.Thread(target=collect) | |
t.start() | |
try: | |
yield | |
finally: | |
please_stop = True | |
t.join() |
Linked PRs
Eclips4