Skip to content

Keep generator control records stable across activations - #10

Draft
maurycy wants to merge 2 commits into
dual-stack-protofrom
generator-stable-control-record
Draft

maurycy wants to merge 2 commits into
dual-stack-protofrom
generator-stable-control-record

Conversation

@maurycy

@maurycy maurycy commented Oct 25, 2026 •

Copy link
Copy Markdown
Owner

Keep generator control records in gi_iframe across resume/yield. Each generator's control-stack slot has a fixed CONTROL_INDIRECT tag; activation state lives only in gi_iframe. Ordinary calls write state directly, and return paths resolve generator slots only when encountered. This avoids copying the record and repointing escaped frame objects. Free-threaded locking is retained.

Base: dual-stack-proto (48370ac99b4); head: 548b797518e.

Across 31 microbenchmarks, runtime geomean is +0.45% and instruction-count geomean is -1.15% versus the base. Results are mixed; this remains an experimental draft.

AMD EPYC 4484PX, GCC 13.3, PGO+LTO, CPU 4; one build per revision. Both use the Tools/dualstack harness at fabb6188. Instructions: N=200,000 and 4N subtraction. Times: geometric means of six interleaved paired process-mean ratios, three values each, one warmup, 50 ms minimum. Negative values mean less time/fewer instructions; individual timing differences may be noise.

Workload Time vs base Instructions vs base
call_return +3.37% -2.35%
call_return_kwargs +0.71% -1.78%
gen_for_loop +1.78% -5.56%
gen_send +0.01% -1.98%
next_from_c -0.41% -1.98%
yield_from_depth5 +3.03% -4.37%
await_chain -1.43% -0.07%
asyncio_pingpong -0.59% -0.64%
recursion_depth200 +7.54% -2.23%
recursion_depth600 -1.13% -2.23%
exception_unwind10 -0.50% -0.03%
init_shim -2.47% -1.66%
property_get -1.89% -2.76%
sort_key_callback +0.18% -1.36%
del_finalizer -0.53% -0.79%
frame_object_access +1.18% -0.26%
frame_noescape -0.30% -0.83%
return_depth10 +3.40% -2.39%
exception_unwind20 -1.32% +0.00%
asyncio_short_tasks +0.26% -0.44%
asyncio_short_tasks_sleep0 -0.68% -0.50%
asyncio_tree_gather +0.63% -0.53%
asyncio_callbacks -0.73% -0.57%
gen_close_finally -1.26% +0.01%
frame_return_drop -1.66% -0.34%
frame_return_fback +1.74% -0.25%
gen_finish_next +0.75% -0.31%
gen_finish_close +3.59% +0.26%
gen_finish_next_frame_held +0.89% +0.82%
gen_finish_close_frame_held -0.53% -0.45%
gen_finish_next_frame_released +1.05% +0.10%

Validation: 2,578 macOS debug tests ran without failures. Linux debug ran 51,729 tests with one failure: generator size 192 vs expected 184 in test_sys, also present on the unchanged base. Free-threaded: 5,536 selected tests plus 40 concurrency tests, no failures. All 15 frame traces matched the base; recursion limits were unchanged; -R 3:3 checks passed for generators, coroutines, async generators and frames. Generated cases and git diff --check are clean.

@maurycy maurycy self-assigned this Oct 25, 2026
@maurycy
maurycy changed the base branch from dual-stack to dual-stack-proto October 25, 2026 22:33
@maurycy
maurycy force-pushed the generator-stable-control-record branch from a08299b to 95a4506 Compare October 25, 2026 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant