Repository navigation
feat(profiling): add opt-in Linux CPU timer stack profiler - #18724
taegyunkim wants to merge 95 commits into
Conversation
Codeowners resolved asResolved from the full PR diff against |
🎉 All green!🧪 All tests passed 🔗 Commit SHA: 873009c | Docs | View more details | Give us feedback! |
BenchmarksBenchmark execution time: 2026-11-18 19:18:14 Comparing candidate commit 873009c in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 625 metrics, 10 unstable metrics, 1 flaky benchmarks without significant changes.
|
|
@taegyunkim do you need help reviewing on this PR ? |
taegyunkim
left a comment
There was a problem hiding this comment.
@r1viollet I'd want to make more changes to this PR. Will let you know when review is needed!
Circular import analysis
|
351ca0e to
3ebcfb0
Compare
## Description Pure refactor of existing stack sampler internals, with no intended behavior or internal contract changes, in preparation for timer_create based cpu time profiling in #18724 Specifically: - Extracts the existing task/greenlet/thread-stack rendering branch in `ThreadInfo::sample()` into a local `render_unwound_stacks()` helper. - Extracts duplicate one-time thread registration failure logging in `Sampler::register_thread()` into a local helper. This does not introduce CPU timer profiling, new configuration, new native bindings, or changes to thread registration semantics. ## Testing - `scripts/lint cformat` Attempted a targeted profiling test run from the worktree, but the test runner failed during riot venv setup before executing tests due the worktree using `/home/bits/project/.riot`, which was not writable/available in that context. ## Risks Low. This is intended to be behavior-preserving refactoring only. ## Additional Notes No changelog needed, internal refactor only. Co-authored-by: taegyun.kim <taegyun.kim@datadoghq.com>
Explain why ThreadAltStack adopts a pre-existing alternate signal stack instead of replacing it: the application, CPython's faulthandler, or libdatadog's crashtracker (which by default creates and owns a larger alt stack) may have installed it, and the destructor must never disable or free an alt stack this object did not allocate. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add a native gtest for ThreadAltStack: an adopted (pre-existing) alternate signal stack must not be disabled on thread-local cleanup, while a stack this helper allocated is disabled and freed. The adopted-stack case fails without the owns_mapping guard, so it locks in this PR's behavior. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…d it ThreadAltStack's destructor disabled whatever alternate signal stack was installed on the thread whenever it owned a mapping, without checking that the installed stack was still the one it installed. If another component (for example libdatadog crashtracker) replaced the thread's alt stack after we installed ours, teardown would strip that replacement, degrading the other owner's fault handling. Only disable the alt stack when it is still ours (cur.ss_sp == mem); free our own mapping regardless. Adds a regression test (DestructorDoesNotDisableReplacedAltStack) that fails without this guard. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
## Description The profiling safe-copy helper uses a per-thread alternate signal stack for its `SIGSEGV` and `SIGBUS` handlers. When an alternate stack was already installed by the application, CPython's faulthandler, or crashtracker, `ThreadAltStack` reused it but still disabled it during thread-local teardown. That could leave the original owner without its alternate stack and weaken its fault handling. Track whether `ThreadAltStack` allocated the mapping itself. Teardown now disables and unmaps only profiler-owned stacks, while adopted stacks remain installed for their original owner. The installation failure path also unmaps a profiler allocation when `sigaltstack()` fails. A release note documents the fault-handling fix. ## Testing - Passed locally: `ddtrace/internal/datadog/profiling/build_standalone.sh -- RelWithDebInfo stack_test` - 4/4 native CTests passed - verifies that an adopted alternate stack remains installed after `ThreadAltStack` teardown - verifies that a profiler-owned alternate stack is disabled during teardown - `scripts/lint cformat` ## Risks Low. The change narrows teardown to resources owned by the profiler and does not alter public APIs or configuration. Profiler-owned alternate stacks retain their existing cleanup behavior. ## Additional Notes Stacked out from the CPU timer profiler work, #18724, to keep this native safety fix independently reviewable. Follow-up PR #19026 handles the complementary case where another component replaces a profiler-owned alternate stack after the profiler installs it. [PROF-14213](https://datadoghq.atlassian.net/browse/PROF-14213) [PROF-14213]: https://datadoghq.atlassian.net/browse/PROF-14213?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ Co-authored-by: taegyun.kim <taegyun.kim@datadoghq.com>
c81693b to
5c01fee
Compare
d4cc4b0 to
12a80a9
Compare
…-timer-create # Conflicts: # ddtrace/internal/datadog/profiling/stack/__init__.pyi # ddtrace/internal/datadog/profiling/stack/_stack.pyi # ddtrace/internal/datadog/profiling/stack/echion/echion/threads.h # ddtrace/internal/datadog/profiling/stack/src/echion/threads.cc # ddtrace/internal/datadog/profiling/stack/src/stack.cpp # ddtrace/profiling/collector/stack.py
…-timer-create # Conflicts: # ddtrace/internal/datadog/profiling/stack/test/CMakeLists.txt
## Description The CPU timer profiler work in #18724 needs to scan lightweight asyncio task identities before constructing `TaskInfo` only for the sampled task and its parents. Today, task-source traversal constructs every `TaskInfo` directly, so it cannot be reused for that path. This PR separates task-address discovery from snapshot construction behind a private visitor. It does not add CPU timer behavior, configuration, or public API. ### Structure Before this change, each Python-version-specific task source constructed `TaskInfo` snapshots directly: ```text task source -> TaskInfo::create() -> loop filter -> wall task list ``` After this change, task sources report addresses through `for_each_task_address()`. Its callback returns `Result<void>`. `get_all_tasks()` supplies the existing wall-sampling materialization and filtering logic, while future sampling paths can supply a lightweight identity callback: ```text /-> TaskInfo::create() -> loop filter -> wall task list task source -> task-address visitor -| \-> future lightweight identity scan ``` ### Traversal semantics - Callback failures stop traversal immediately and propagate through `Result<void>` without exceptions. - Wall sampling preserves best-effort handling of individually unreadable tasks by returning success from its callback when `TaskInfo::create()` fails. - Python 3.14 circular-list traversal returns addresses from `get_task_addresses_from_linked_list()` only after the complete list passes the consistency checks from #19798. - A malformed Python 3.14 linked-list snapshot publishes no addresses and is treated as an empty source, allowing discovery to continue with other sources. ### Preserved invariants - Task sources, source order, and source availability checks are unchanged. - Python 3.14 per-thread and per-interpreter lists are visited only when both `tstate` and `tstate_addr` are available. - Validated linked-list addresses retain their original order. - Wall sampling retains its existing event-loop filtering and Python 3.14 cross-source deduplication policy. - Pre-Python 3.14 behavior is unchanged, including its existing lack of cross-source deduplication. ## Testing - Based on `origin/main` at `1474aa5746`. - Built and ran the standalone native `stack_test` target in `RelWithDebInfo` mode with warnings as errors against: - CPython 3.10.12, 22/22 tests passed. - CPython 3.14.5, 26/26 tests passed, including malformed-list publication, callback error propagation and early termination, and cross-source deduplication coverage. - Ran `scripts/lint cformat`. - Ran `scripts/lint profiling-native-check`. - Ran `scripts/lint checks`. - An earlier CPython 3.10 wall-profiler benchmark with 500 suspended tasks and fixed 1 ms sampling showed no measurable regression, with baseline and candidate medians overlapping around 0.44 CPU seconds. ## Risks Low. The extraction is private and retains the existing wall-sampling construction and filtering path. Python 3.14 linked-list traversal temporarily stores task addresses before invoking the visitor so malformed sources cannot expose partial results. The vector is bounded by the existing 65,536-node traversal limit and stores pointers rather than `TaskInfo` snapshots. ## Additional Notes No release note is needed because this is an internal, behavior-preserving refactor. Co-authored-by: taegyun.kim <taegyun.kim@datadoghq.com>
Adopt main's Result-returning task address visitor and expanded native traversal tests. Adapt CPU timer task identity collection and the renamed stack unwind safety limit. Validation: full scripts/lint checks; 34 CPython 3.12.13 and 37 CPython 3.14.5 native stack tests passed. Python integration runner remains blocked by container worktree/cache permissions. Benchmark discovery found no matching suite.
| const pid_t current_tid = raw_gettid(); | ||
| for (auto& item : g_state.live_by_thread_id) { | ||
| CaptureState& state = *item.second; | ||
| if (current_tid == static_cast<pid_t>(state.native_tid)) { |
There was a problem hiding this comment.
this check will not work as the thread id is different in child
There was a problem hiding this comment.
#!/usr/bin/env python3
"""Reproduce ddtrace's dangling alternate signal stack after fork on Linux."""
import faulthandler
import os
import signal
import threading
import time
# These must be set before importing ddtrace.
os.environ["DD_PROFILING_OUTPUT_PPROF"] = "/tmp/ddtrace-postfork-altstack"
os.environ["_DD_PROFILING_STACK_ADAPTIVE_SAMPLING_ENABLED"] = "0"
os.environ["_DD_PROFILING_STACK_CPU_TIMER_ENABLED"] = "1"
os.environ["_DD_PROFILING_STACK_CPU_TIMER_INTERVAL_MS"] = "1"
from ddtrace.profiling import profiler
faulthandler.register(signal.SIGUSR1)
p = profiler.Profiler()
p.start()
result = []
def fork_from_profiled_worker():
# Give the sampler time to discover this worker and install its stack.
deadline = time.thread_time() + 0.1
while time.thread_time() < deadline:
pass
pid = os.fork()
if pid == 0:
# ddtrace's at-fork hook unmapped the still-registered alt stack.
signal.raise_signal(signal.SIGUSR1)
os._exit(0)
result.append(os.waitpid(pid, 0)[1])
thread = threading.Thread(target=fork_from_profiled_worker)
thread.start()
thread.join()
p.stop()
assert os.waitstatus_to_exitcode(result[0]) == -signal.SIGSEGV, result[0]
print(f"wait status={result[0]} core={os.WCOREDUMP(result[0])}")
print("reproduced: SA_ONSTACK signal crashed the fork child with SIGSEGV")…-timer-create # Conflicts: # ddtrace/internal/datadog/profiling/stack/include/sampler.hpp # ddtrace/internal/datadog/profiling/stack/src/sampler.cpp # ddtrace/internal/datadog/profiling/stack/src/stack.cpp
…after fork The child's postfork handler identified the forking thread by its parent TID, which changes across fork, so it unmapped the alt stack that thread still had installed. Later SA_ONSTACK signals then ran on freed memory, either crashing or corrupting whatever the child mapped there next. Identify the in-use alt stack by the inherited sigaltstack setting instead, keep that mapping, and hand it to the thread's new CaptureState when it registers again in the child.
…changes Keep the CPU timer engine alive through exit like the other stack sampler singletons, since the sampling thread can still drain it when uWSGI exits without running the atexit hooks. Add Python 3.15 to the unpinned protobuf row that runs with and without the CPU timer, so that row keeps covering 3.15 as main now expects.
… drain On Python 3.14+, the sampler clears the frame identity caches when a code object generation changes, but only did so inside the wall sampling cycle. The CPU timer drain runs on its own deadline and reads the same caches, so it could resolve a reused code object address to a stale cached frame. Snapshot interpreters and validate code object generations once per loop iteration, before either the drain or the wall sample. Wall sampling still skips the cycle when the snapshot is incomplete. The drain still runs, since the caches were cleared and skipping would let the rings fill.
…-timer-create # Conflicts: # ddtrace/internal/datadog/profiling/stack/CMakeLists.txt # ddtrace/internal/datadog/profiling/stack/src/sampler.cpp # ddtrace/internal/datadog/profiling/stack/src/stack.cpp
… table On Python 3.14, the CPU timer signal handler read asyncio_running_task at its compile-time offset in _PyThreadStateImpl. That offset can differ from the running 3.14 patch release, which loses task identity for CPU samples. Take it from CPython's AsyncioDebug table, together with the task-list head offsets. Until the table is found, CPU samples carry no running-task identity, matching how the task lists are skipped.
…tself On CPython 3.13+, threading._after_fork() calls _set_native_id() on the forking thread, so the child registers it twice. The second registration took our own alt stack for an application one, and retiring the first state then unmapped it. Hand the stack to the replacing state instead.
…-timer-create # Conflicts: # ddtrace/internal/datadog/profiling/stack/src/echion/danger.cc # ddtrace/internal/datadog/profiling/stack/src/sampler.cpp
Note
Thorough manual review is still in progress.
Description
Adds an opt-in Linux CPU timer path for the stack profiler on standalone, GIL-enabled CPython 3.12+. Enable it with
_DD_PROFILING_STACK_CPU_TIMER_ENABLED=true; the default interval is 10 ms and the feature remains off by default. Embedded interpreters, including uWSGI, retain wall-sampled CPU time because the host process owns the signal handlers.Each Python thread receives a
timer_createper-thread CPU timer that deliversSIGPROFthroughSIGEV_THREAD_ID. The signal handler validates that the signal came from this profiler, captures bounded raw frame and task identity data into a preallocated per-thread SPSC ring, and returns without allocating or locking. The sampler thread drains the rings, validates copied CPython data, and emitscpu-timesamples with asyncio task or greenlet ancestry when the captured identity can be matched safely.Wall sampling continues independently. When CPU timer mode is configured, wall samples stop reporting CPU time so the process does not mix accounting methods if the timer later disables itself.
Safety and lifecycle handling includes:
SIGPROFsignals to the previous handlerAsyncioDebugtablePROF-14213
Testing
Latest main merge (
e0ef38abe3,origin/mainat69a914db1d):previous_task_objects(), which this PR does not use. The CPU timer only reads the link maps under their lock.render_frameandrender_native_framepaths, which CPU timer samples also use.scripts/run-testsafter a native rebuild:test_cpu_timer_postfork_from_worker_keeps_inherited_altstack.test_task_links.Previous main merge (
85ab528e1d, merged in25bfe9e603,origin/mainatec346212b5):stack/CMakeLists.txt,sampler.cpp, andstack.cpp:cpu_timer.cppalongside main's new asyncio debug-offset sources from fix(profiling): read Python 3.14 asyncio task offsets from the runtime #21278fast_copy_handler_ops_enabled()guard instack_uninstall_segv_handlerand still disable the CPU timer right before our SIGSEGV/SIGBUS handlers are removed. Main now removes them during fast-copy warmup too, so the CPU timer is disabled in that case as well.render_cpu_sample_beginnow usesget_active_span(SpanLinkKey::thread(...)), matching main's other call sites.scripts/run-testsafter a native rebuild:test_cpu_timer_postfork_from_worker_keeps_inherited_altstackdescribed below.asyncio_running_taskat the offset from the sameAsyncioDebugtable instead of its compile-time offset. Until the table is found, CPU samples carry no running-task identity, matching how the task lists are skipped._asynciomodule returnsoffsetof(_PyThreadStateImpl, asyncio_running_task).test_cpu_timer_reads_asyncio_running_task_offset_from_runtime_table: the offset is published from the runtime table on 3.14 and stays 0 before 3.14. CPython 3.14 CPU timer and asyncio tests: 113 passed, with only the pre-existing postfork failure. CPython 3.12 CPU timer tests: 28 passed for both command variants.scripts/lint cformatpassed.Previous main merge (
23d472aa45,origin/mainatc78138ab81):140f6d4884). Three follow-up changes adapt the CPU timer to main:CpuTimer::Engine::get()now follows the same pattern, since the sampling thread drains it.profilerow to cover it. This PR had split that row into explicit 3.9 to 3.11 and 3.12 to 3.14 lists, so 3.15 was added to the row that runs with and without the CPU timer.-k "cpu_timer or stack") throughscripts/run-testsafter a native rebuild:test_cpu_timer_postfork_from_worker_keeps_inherited_altstack: in the child, the inherited alt stack is counted as an application alt stack. It fails the same way at the pre-merge head153b71e03f, so it is not a regression from this merge, and it still needs a fix. It passes on 3.12.scripts/lint cformat,scripts/lint suitespec-check, andscripts/lint suitespec-duplicatespassed.Previous main merge (
153b71e03f,origin/mainat5d92793a3b):EchionSampler. The CPU timer does not walk those lists in the signal handler; it reads onlyasyncio_running_task, which is not one of the moved offsets, so no CPU timer change was needed.scripts/run-testsafter a native rebuild: 532 passed, 45 skipped, and 3 expected failures for both command variants, including 44 CPU timer test passes and 2 gevent skips. The two additional passes are new scheduler tests from main.Previous main merge (
198e00f81e,origin/mainatc9ceaa6a7b):scripts/run-testsafter a native rebuild: 530 passed, 45 skipped, and 3 expected failures for both command variants, including 44 CPU timer test passes and 2 gevent skips.Previous main merge and fork alt-stack fix (
b72870b0bd,origin/mainat1cb9f945a5):origin/mainat1cb9f945a5(8af359af29). Resolved conflicts insampler.hpp,sampler.cpp, andstack.cpp:register_fork_cleanup()alongside thePyThreadState*parameter onSampler::register_threadPyThreadStatecheckEngine::postfork_child()identified the forking thread by its parent TID, which changes across fork, so the child unmapped the alt stack that thread still had installed. The child now finds the in-use mapping from the inheritedsigaltstacksetting, keeps it mapped, and hands it to the thread's new capture state when it registers again. Mappings no longer in use are still released.test_cpu_timer_postfork_from_worker_keeps_inherited_altstack, which forks from a profiled worker thread, delivers anSA_ONSTACKsignal in the child, and checks that the child keeps CPU timer sampling without mistaking the inherited stack for an application one. Without the fix, the test fails because the child reuses the freed mapping as an application alt stack. A crash is not guaranteed, since the child's own allocations can land on the freed range, which later signals then overwrite. The existing fork test forks from the main thread, whose alt stack is echion's and was never unmapped, so it did not cover this.scripts/run-testsafter a native rebuild: 530 passed, 45 skipped, and 3 expected failures, including both CPU timer command variants (44 CPU timer test passes, 2 gevent skips).scripts/lint cformatandscripts/lint styleon the changed files passed. Both new commits are signed and verified.Previous main merge validation (
e16880aa58,origin/mainata1bcb762e9):riotfile.py, retaining CPU-timer-enabled runs intests/profiling/suitespec.yml.RelWithDebInfostandalone build: all 51 native stack tests passed, including the new signal-chaining tests.scripts/run-tests:ppollinterruption reproducer. This was targeted validation, not a full profiling-suite run.scripts/lint cformat,scripts/lint profiling-native-check,scripts/lint checks, and whitespace checks relative toorigin/mainpassed. Benchmark discovery found no matching suite for the resolved fault-handler source.Earlier build repair and main refresh (
8663153a7d):python_headers.hppwas removed by replacing the stale include incpu_timer.hppwith the direct CPython include and compatibility guard.origin/mainat9379ddd518, preserving both CPU timer sampling and the new native frame-limit propagation.uv build --wheeland rebuilt the CPython 3.13_stackCMake target with warnings treated as errors.scripts/run-tests: 52 passes total, 2 skips, and 2 expected failures.scripts/lint cformat, fullscripts/lint checks, andgit diff --checkpassed.Earlier main refresh (
03d23af35d):scripts/run-tests --dry-runconfirms both runs reuse the existing dependency locks.scripts/lint checksandgit diff --check origin/mainpassed.13657704944520646691showed deterministic worker crashes in the CPU-timer-enabled uWSGI tests on Python 3.12 through 3.14; the matching normal profiling runs passed.SIGSEGVduring Python fork callbacks after CPU timer profiling installed its signal handlers.scripts/run-testswas attempted, but the required native rebuild failed when the linker receivedSIGBUSwith only 2 GB of disk space left. Mosaic request9276649356139908723passed, including all 23 profiling shards, all five uWSGI profiling shards, the CPU-timer-enabled Python 3.12 through 3.14 runs, the Python 3.15 base virtualenv build, and downstream system tests.prof-14213-cpu-timeris ready forrapid_python_http_smoke_testfrom dd-source commitcb189b915f1c, using the integration wheel and_DD_PROFILING_STACK_CPU_TIMER_ENABLED=true. Deployment request233155852796473320passed. Runtime diagnostics confirm the 10 ms CPU timer remains active with no capture failures, overruns, or health disablement. No samples were dropped during an 18-second CPU-heavy burst; one worker reported 170 ms of earlier startup ring-buffer drops. In a stable one-minute bucket, Python CPU time was 0.828 cores versus 0.817 container cores.signal-bundlerwith the latest PR head8663153a7d, integration wheelaecedeca6e, and dogweb artifactv137405555-88becf86. Conductor run5b0930c0-cbf6-472c-9f4b-14b4f3e27c18completed successfully. All 25 active service pods became ready with zero restarts and published Python 3.12 profiles fromddtrace4.15.0rc2, including CPU-time stacks in normal message-processing paths. Service logs contained no CPU timer, profiler failure, fatal Python, or segmentation fault messages during rollout.FRAME_OWNED_BY_CSTACK; the CPU timer now uses the same version guard as the existing Echion frame reader.scripts/lint cformatpassed, and benchmark discovery found no matching suite for this compile-only guard.scripts/lint fmt -- ddtrace/internal/settings/profiling.py,scripts/lint checks, targeted style and spelling checks, andgit diff --checkpassed.Coverage includes:
ppoll,read/readv, andnanosleepvariantsscripts/lint cformat,scripts/lint profiling-native-check,scripts/lint checks, andgit diff --checkb16f02e665with CPython 3.10 and 3.14 release native builds, all 29 native stack tests, and 251 correctly attributed, parent-stitched Python 3.14 asyncio CPU samples5a9dafde4dwith a CPython 3.12RelWithDebInfostandalone build and all 34 native stack tests after adopting the native span-link manager renameOn a CPython 3.12 workload with 501 asyncio tasks, selective task reconstruction reduced median CPU timer drain cost from about 2.82 seconds to 0.249 seconds, a 91% reduction, while preserving attribution and wall-sample recovery.
Risks
This path depends on asynchronous signals and version-specific CPython frame layouts. It is Linux-only, private, opt-in, disabled by default, and disabled in embedded interpreters. Unsupported or unsafe runtime conditions disable CPU timer sampling rather than falling back to mixed CPU accounting.
A pending
SIGPROFcan interrupt a native extension syscall that neither masks the signal nor retriesEINTR. CPython's PEP 475 paths retry affected syscalls, and the test suite documents the remaining rawppolllimitation with an expected-failure reproducer.Additional Notes
Signature-only history update:
fd976174d3is now signed asfdc9363203, and its ten descendants were re-signed. Every rewritten commit retains its original file tree, message, authorship, dates, and merge relationships.#19428 now bounds the number of leaf task and greenlet samples emitted by each wall-sampling cycle. CPU timer samples remain outside that reservoir because each signal sample matches at most one captured task or greenlet and emits one CPU sample.
PRs spun out from this work
Span-to-profile correlation is covered by the separate span-attribution chain spun out from this work. It keeps correlation working for physical thread stacks, asyncio task stacks, and greenlet stacks:
Prerequisites already merged into
main:chore(profiling): fix native coverage check #18973, fixes and enables the profiling native coverage check
refactor(profiling): split stack sampler helpers #18975, extracts stack sampler rendering and registration helpers
fix(profiling): track signal altstack ownership #19018, tracks alternate signal stack ownership
fix(profiling): don't disable an alt stack replaced after we installed it #19026, preserves an alternate signal stack installed by another component
fix(profiling): align frame limit with backend location cap #19076, aligns the frame limit with the backend location cap
perf(profiling): consolidate greenlet switch updates #19655, consolidates greenlet switch recording through the private
record_greenlet_switch()APIci(profiling): remove duplicate fast-copy profile runs #19684, removes redundant explicit fast-copy full-suite runs
ci(profiling): remove duplicate gevent environment #19686, removes the duplicate Python 3.10 gevent environment
Additional prerequisites now merged into
main:refactor(profiling): separate task address discovery #19709, shares task-source traversal through an address visitor while preserving immediate wall-task snapshots
fix(profiling): respect frame limits during native stack collection #19073, propagates the configured maximum frame count through native stack collection
refactor(profiling): clarify stack unwind safety limit #20352, clarifies the internal stack unwind safety limit
Open max-frame prerequisite:
Cache sizing is intentionally outside this stack. This branch already retains the fixed 1024-entry frame cache and contains none of #20351's dynamic cache-scaling changes. Evaluate #20351 after #19085 and the rest of the stack have merged; it is not a prerequisite.
Independent test hardening already merged into
main: