startup: start the debugged process without the debug heap #1643

Merged
rm-NoobInCoding merged 1 commit from upstream-pr/1650 into main 2026-11-24 16:21:16 +00:00
rm-NoobInCoding commented 2026-11-24 16:03:26 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by rm-NoobInCoding on 2026-11-24T16:03:26Z.


Change

A process that Windows creates under a debugger gets the debug heap: the loader sets the heap tail-check, free-check and parameter-validation flags (NtGlobalFlag 0x70) and the low-fragmentation heap is not used, so every allocation and free in the debugged process costs more. tools/startup/debug_launch.py creates the title under its debugger, so every startup run paid that cost.

debug_launch.py now starts the process with _NO_DEBUG_HEAP=1 unless the environment already sets _NO_DEBUG_HEAP. Setting _NO_DEBUG_HEAP=0 keeps the debug heap, for example to look for heap corruption. Nothing else about the launch changes. docs/startup-runtime.md describes the default and the override in the Run section.

No shared interface changes.

Verification

Base 874cc3fa, patch 35ea852e. Windows 11 build 26300, MSVC 19.51.36260, dev preset (Debug), Python 3.11 from out/pe-env.

cmake --build --preset dev --target startup_debug_probe
ctest --preset dev --no-tests=error -R '^startup_debug$' --output-on-failure

Result: 1/1 passed, no skips. startup_debug_probe now prints the heap bits of its PEB NtGlobalFlag; the check requires 0x0 in the baseline run and 0x70 in a run with _NO_DEBUG_HEAP=0. The check removes any inherited _NO_DEBUG_HEAP before each run, so the host environment cannot decide the result.

Negative control. With only debug_launch.py reverted to the base, the baseline assertion fails:

AssertionError: debug-probe reserved ok
debug-probe heap flags 0x70

python -B tests/docs_links_check.py: self-test passed, 16 Markdown files and 348 links. python -B tests/bidi_controls_check.py: no bidirectional controls.

Evidence and follow-up

Local diagnostic runs of a console executable on the Release startup stand-ins (tools/startup/run.ps1 -Render -FakeUser -GpuMirror -HostCpu, RTX 4070); raw logs, pointers, binaries and captures are not attached. Times are from the debugger's file and event logs and the DirectStorage heartbeat.

With temporary timing around local_apply in src/xmem_mapped_pages.cpp (not part of this PR), one XMemMapPhysicalPages call of 99,776 pages took:

debug heap (default before) _NO_DEBUG_HEAP=1
one-view-per-page 12,294 ms (OS mapping 3,331 ms) 458 ms (OS mapping 441 ms)
X2W_XMEM_SHARED_VIEWS=1 10,270 ms (OS mapping 1,369 ms) 54 ms (OS mapping 38 ms)

About 8.9 s of each debug-heap call came after the OS mapping finished: thread samples taken during it were freeing the nodes of the call's 99,776-entry std::map. At the run level, the first DirectStorage batch (3,254 requests) completed by the 10 s heartbeat instead of the 30 s one, and the title's first video open moved from about 20–25 s to about 5–8 s.

The rest of the startup wait is not addressed here. After that first video open, each run waited about 45 s before the next video started, before and after this change, while the title polled one runtime provider about 100 times per second.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6586029976 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1650). Originally posted by [rm-NoobInCoding](https://github.com/rm-NoobInCoding) on 2026-11-24T16:03:26Z. --- ## Change A process that Windows creates under a debugger gets the debug heap: the loader sets the heap tail-check, free-check and parameter-validation flags (`NtGlobalFlag` 0x70) and the low-fragmentation heap is not used, so every allocation and free in the debugged process costs more. `tools/startup/debug_launch.py` creates the title under its debugger, so every startup run paid that cost. `debug_launch.py` now starts the process with `_NO_DEBUG_HEAP=1` unless the environment already sets `_NO_DEBUG_HEAP`. Setting `_NO_DEBUG_HEAP=0` keeps the debug heap, for example to look for heap corruption. Nothing else about the launch changes. `docs/startup-runtime.md` describes the default and the override in the Run section. No shared interface changes. ## Verification Base `874cc3fa`, patch `35ea852e`. Windows 11 build 26300, MSVC 19.51.36260, `dev` preset (Debug), Python 3.11 from `out/pe-env`. ```powershell cmake --build --preset dev --target startup_debug_probe ctest --preset dev --no-tests=error -R '^startup_debug$' --output-on-failure ``` Result: 1/1 passed, no skips. `startup_debug_probe` now prints the heap bits of its PEB `NtGlobalFlag`; the check requires `0x0` in the baseline run and `0x70` in a run with `_NO_DEBUG_HEAP=0`. The check removes any inherited `_NO_DEBUG_HEAP` before each run, so the host environment cannot decide the result. **Negative control.** With only `debug_launch.py` reverted to the base, the baseline assertion fails: ``` AssertionError: debug-probe reserved ok debug-probe heap flags 0x70 ``` `python -B tests/docs_links_check.py`: self-test passed, 16 Markdown files and 348 links. `python -B tests/bidi_controls_check.py`: no bidirectional controls. ## Evidence and follow-up Local diagnostic runs of a console executable on the Release startup stand-ins (`tools/startup/run.ps1 -Render -FakeUser -GpuMirror -HostCpu`, RTX 4070); raw logs, pointers, binaries and captures are not attached. Times are from the debugger's file and event logs and the DirectStorage heartbeat. With temporary timing around `local_apply` in `src/xmem_mapped_pages.cpp` (not part of this PR), one `XMemMapPhysicalPages` call of 99,776 pages took: | | debug heap (default before) | `_NO_DEBUG_HEAP=1` | |---|---|---| | one-view-per-page | 12,294 ms (OS mapping 3,331 ms) | 458 ms (OS mapping 441 ms) | | `X2W_XMEM_SHARED_VIEWS=1` | 10,270 ms (OS mapping 1,369 ms) | 54 ms (OS mapping 38 ms) | About 8.9 s of each debug-heap call came after the OS mapping finished: thread samples taken during it were freeing the nodes of the call's 99,776-entry `std::map`. At the run level, the first DirectStorage batch (3,254 requests) completed by the 10 s heartbeat instead of the 30 s one, and the title's first video open moved from about 20–25 s to about 5–8 s. The rest of the startup wait is not addressed here. After that first video open, each run waited about 45 s before the next video started, before and after this change, while the title polled one runtime provider about 100 times per second. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted.
upstream-sync closed this pull request 2026-11-24 17:01:48 +00:00
tedin7 commented 2026-11-24 17:01:49 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T16:19:15Z.

Review: COMMENTED


Peer review of PR #1650 (35ea852e9f7a9065cc599018a6f203504b323768).

Findings

  • No defects found.
  • tools/startup/debug_launch.py sets env.setdefault("_NO_DEBUG_HEAP", "1") before building the CreateProcessW Unicode environment block, and tests/startup_debug_check.py strips _NO_DEBUG_HEAP (case-insensitively) from the inherited test environment before verifying both the default (debug-probe heap flags 0x0) and _NO_DEBUG_HEAP=0 (debug-probe heap flags 0x70).
  • Title-neutral and clean across all 4 changed files (docs/startup-runtime.md, tests/startup_debug_check.py, tests/startup_debug_probe.cpp, tools/startup/debug_launch.py).

Verification

  • Linux:
    • python3 -m py_compile /tmp/rev-x2w-75/1650/tools/startup/debug_launch.py /tmp/rev-x2w-75/1650/tests/startup_debug_check.py -> passed.
  • Win2025 Debug (--preset dev):
    • python3 /root/.local/state/xbox2windows/pipeline/x2w_pipe.py win2025 1650 --wait 120 -> 3/3 passed (startup_host_cpu_debug 0.33s, startup_run_ps1 2.98s, startup_debug 22.10s).
  • Win2025 Release /O2 (--preset release):
    • Same x2w_pipe.py win2025 run -> 3/3 passed (startup_host_cpu_debug 0.34s, startup_run_ps1 2.90s, startup_debug 22.08s).
  • Local mutation check:
    • Temporarily removed env.setdefault("_NO_DEBUG_HEAP", "1") in tools/startup/debug_launch.py and verified the default launch environment no longer sets _NO_DEBUG_HEAP (the Windows probe in tests/startup_debug_check.py asserts debug-probe heap flags 0x0\n by default and 0x70 when _NO_DEBUG_HEAP=0). Reverted cleanly with git checkout -- ..

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6043103769 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1650#pullrequestreview-6043103769). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T16:19:15Z. **Review:** COMMENTED --- Peer review of PR #1650 (`35ea852e9f7a9065cc599018a6f203504b323768`). ### Findings - No defects found. - `tools/startup/debug_launch.py` sets `env.setdefault("_NO_DEBUG_HEAP", "1")` before building the `CreateProcessW` Unicode environment block, and `tests/startup_debug_check.py` strips `_NO_DEBUG_HEAP` (case-insensitively) from the inherited test environment before verifying both the default (`debug-probe heap flags 0x0`) and `_NO_DEBUG_HEAP=0` (`debug-probe heap flags 0x70`). - Title-neutral and clean across all 4 changed files (`docs/startup-runtime.md`, `tests/startup_debug_check.py`, `tests/startup_debug_probe.cpp`, `tools/startup/debug_launch.py`). ### Verification - **Linux**: - `python3 -m py_compile /tmp/rev-x2w-75/1650/tools/startup/debug_launch.py /tmp/rev-x2w-75/1650/tests/startup_debug_check.py` -> passed. - **Win2025 Debug (`--preset dev`)**: - `python3 /root/.local/state/xbox2windows/pipeline/x2w_pipe.py win2025 1650 --wait 120` -> **3/3 passed** (`startup_host_cpu_debug` `0.33s`, `startup_run_ps1` `2.98s`, `startup_debug` `22.10s`). - **Win2025 Release `/O2` (`--preset release`)**: - Same `x2w_pipe.py win2025` run -> **3/3 passed** (`startup_host_cpu_debug` `0.34s`, `startup_run_ps1` `2.90s`, `startup_debug` `22.08s`). - **Local mutation check**: - Temporarily removed `env.setdefault("_NO_DEBUG_HEAP", "1")` in `tools/startup/debug_launch.py` and verified the default launch environment no longer sets `_NO_DEBUG_HEAP` (the Windows probe in `tests/startup_debug_check.py` asserts `debug-probe heap flags 0x0\n` by default and `0x70` when `_NO_DEBUG_HEAP=0`). Reverted cleanly with `git checkout -- .`. AI-assisted; commands listed were executed locally.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!1643
No description provided.