perf: freeze the heap AppHarness started until it stops
Ā
BE
43m ago+77+77+01234567890123456789-0-0-0123456789
Summary
AppHarness.start()now ends withgc.collect(); gc.freeze(), once the app is built and running.stop()callsgc.unfreeze(), so the next harness in the session can collect this one's objects.- The harness compiles and runs the app inside the test process, and the app stays alive until
stop(). Until then every full collection walks all of it. The collection holds the GIL, so the backend thread's event loop stalls for the whole pass. - The harness runs the app in dev mode, where the blocking detector (
event_loop_blocking_threshold, default 0.2 s) reports such a stall as a blocking event handler. That can fail tests that check the console output. - Production workers already freeze the built app (#7079, #7945).
Measurement
The test app was generated: 400 states, each with 10 fields and 10 computed vars, plus 400 pages. It was started through AppHarness.start() on Python 3.14.8. The table counts tracked objects and times a full gc.collect() (range of 3 runs) at two points: right before the freeze, and after start() returned.
| tracked objects | full gc.collect() | |
|---|---|---|
| started, unfrozen | 914,616 | 350ā430 ms |
after start() (frozen) | 1 | < 0.1 ms |
A larger app reaches 5.2M tracked objects under the harness, and a full collection there takes 2.2ā2.5 s.
Costs
start()runs one extra full collection.stop()unfreezes everything, including anything the test session froze itself. A conftest that freezes its own heap has to freeze again after a harness stops.- A frozen object that becomes unreachable through a reference cycle is only collected after
stop(). Reference counting still frees everything else.
Test plan
-
test_app_harness_freezes_the_started_app_until_stoppedchecks three states. Nothing is frozen during the start steps, the heap is frozen while the app runs, and nothing is frozen afterstop(). It fails without the change. -
uv run pytest tests/units - Integration:
test_background_taskandtest_client_storage -
ruff check,ruff format --check,pyright - Manual: the table above.
š¤ Generated with Claude Code