[PR #4058] [MERGED] Add an opt-in Windows Segment Heap build feature #5388

Closed
opened 2026-11-03 05:12:15 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4058
Author: @ult1mq
Created: 10/29/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @rdbtCVS

Base: main ← Head: codex/windows-allocator-options


📝 Commits (3)

  • 93f42ea Add independent opt-in Windows allocator build features
  • 5a453aa Merge main into Windows allocator options
  • ca27b2d Merge main and preserve the upstream mimalloc allocator

📊 Changes

5 files changed (+100 additions, -1 deletions)

View changed files

📝 crates/horizon-client/Cargo.toml (+4 -0)
📝 crates/horizon-client/build.rs (+7 -1)
➕ crates/horizon-client/windows-segment-heap.manifest (+17 -0)
📝 docs/native-client.md (+3 -0)
➕ docs/windows-allocators.md (+69 -0)

📄 Description

🤖 Opened by ult1mq's AI agent (Codex, GPT-6), not by ult1mq personally.

What and why

Rapid flight produced short frame-time spikes on one Windows machine. Native profiling pointed to contention in the Windows heap path. This PR adds an off-by-default windows-segment-heap Cargo feature so maintainers can measure the Win32 heap choice on the current client.

Main has since merged #4160, which already makes mimalloc the game's global allocator. This PR preserves horizon_threads::Allocator, its startup configuration, memory-release behavior, and dependencies exactly as they are on main. The earlier windows-mimalloc feature name remains accepted as a documented compatibility no-op; it adds no dependency and does not select a second allocator.

windows-segment-heap embeds a manifest through the existing Windows-host winresource step, alongside the unchanged icon and version resources. It requests asInvoker, without elevation, and affects Win32 heap APIs that native libraries can still use alongside mimalloc. Non-Windows builds retain main's behavior. Cross-compiling these resources from a non-Windows host is not supported by the existing build step. No world streaming, meshing, rendering or gameplay code is changed.

The Windows allocator experiment guide describes the current mimalloc baseline, the Segment Heap build, final-PE manifest inspection and controlled measurements. Changing the heap option requires rebuilding and restarting; it is not a runtime switch or mod. Segment Heap support starts at Windows 10 version 2004/build 19041, per Microsoft's manifest specification.

Fixes #4042

Kind

  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • perf: faster, or less memory
  • feature: something new for players (listed under New in the release notes)
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Vanilla reference

Horizon-only native allocation/build configuration. No vanilla gameplay behavior is changed.

Evidence and limits

The motivating measurements used the older nightly baa379d71777f06a95b4e7650b2209a3d4209033, not the current mimalloc-based PR base 8f376a471. They compare the stock executable with a candidate whose only intentional change was the embedded Segment Heap manifest. A PE comparison verified unchanged non-resource sections and preserved original icon/version resources. This supports trying Segment Heap on that machine; it is not a benchmark of this source integration or evidence of a benefit on the current mimalloc-based client.

Historical variant Frames / measured seconds Average FPS p99 frame time Maximum frame time
Stock nightly 3,027 / 31.99 s 94.63 36.59 ms 54.67 ms
Same nightly, Segment Heap manifest only 4,432 / 32.02 s 138.43 10.78 ms 29.57 ms

Historical SegmentHeap manifest-only measurements

Sanitized timing arrays, plotting script, reproduction protocol and limitations.

Hardware: Intel Core i9-13900K, NVIDIA RTX 3090, 2560×1440, Vulkan, Windows 11 build 26200. Each variant used a fresh copy of the same world, warmed at render distance 64 for 20 seconds, returned to render distance 16/simulation distance 9/LOD distance 64 with full LOD, waited 12 seconds, then made four 256-block flights lasting eight seconds each. Game FPS limit: 160. The display is 165 Hz; a later read-only NVAPI inspection found a global driver VSync override enabled even though game VSync was off. These are whole-system frame times under those caps, not uncapped throughput.

One machine and one sequential session per variant are insufficient for a general performance claim. Four flight passes are not four independent trials. Load order, world scheduling, driver behavior and run-to-run variance remain limitations. The raw per-pass values are included with the graph/evidence attachment.

There is no isolated mimalloc measurement. A later custom build combined mimalloc, Segment Heap, mesh buffer reuse and LOD retirement changes. Its results cannot establish mimalloc's contribution or be attributed to this PR. Likewise, the later 165 FPS result was display/driver capped and used a different warm-up period; it does not establish this PR's maximum FPS.

Segment Heap remains off by default. New controlled measurements must compare current main's mimalloc baseline against that same client plus Segment Heap. The legacy windows-mimalloc feature cannot measure system allocation versus mimalloc. Broader Windows/hardware results are still needed; no new performance measurement is claimed for this merge.

Self-check

Merged current main (8f376a471237775e521e910a834a552244e12207) into the existing PR branch with both parents preserved. No rebase or force push.

The conflicts in Cargo.lock and client main.rs were resolved by taking current main unchanged. The PR now changes five files, +100/-1: Cargo feature declarations, the resource build step, the manifest, the experiment guide, and its existing native-client guide link. It makes no lockfile or allocator implementation changes relative to main. An independent review of the resolution found no actionable issues.

pr_ready (tools/pr_ready.py --quick on local Windows (host name redacted), against origin/main at 8f376a471, 2 min 52 s)

Check Result
Scope ✅ 5 files, +100 −1
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ❌ 481 run, FAILED (failures=1, skipped=11) (39 s)
rustfmt ✅ (6 s)
clippy ✅ (38 s)
tests: horizon-client ❌ 781 passed, 1 failed (1 min 24 s)
doc tests ✅ 0 passed (1 s)
content root tests ➖ content root untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ not run (--quick): CI's parity job picks the affected harnesses
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

All four retained Windows MSVC command combinations passed cargo check --locked -p horizon-client --bin horizon-client: baseline, windows-segment-heap, compatibility windows-mimalloc, and both. The latter two do not introduce another allocator variant. These checks execute the resource build step and type-check the client; they do not link or launch a full game.

The actual resolved build.rs was also compiled and exercised with two linked minimal Windows PE probes. mt.exe extracted and validated manifest resource #1; the SegmentHeap namespace/value and asInvoker were verified. All nine icon/group-icon/version payloads matched the baseline byte for byte. The baseline had no SegmentHeap manifest, and a Linux target emitted no Windows resource. No game was launched. The public-tree history check and PR-delta whitespace check passed.

The Python suite ran 481 tests with one failure and 11 skips. Its Windows failure in WorkspaceManifestTests.test_a_feature_of_a_workspace_crate_counts_through_its_sources was independently reproduced with the exact focused test on untouched current main 8f376a471 in a clean detached worktree.

The client library ran 781 passing tests, one failure and 20 ignored tests. title::tests::each_world_preset_writes_its_own_generator failed with Windows OS error 267 for a preset-ID directory containing a colon. This is the same Windows fixture failure previously reproduced on the untouched earlier base; the fixture is identical to current main, but a separate current-main Rust baseline run was not performed. Library failure stops subsequent binary/integration test targets, so those are not claimed as tested. Earlier untouched-base Windows failures. No unrelated fixture changes are included in this PR.

Vanilla parity harnesses were not run locally (--quick); the self-check lists their scope. The historical graph above is separate from validation of this updated merge.

🤖 Generated with Codex.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/4058 **Author:** [@ult1mq](https://github.com/ult1mq) **Created:** 10/29/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@rdbtCVS](https://github.com/rdbtCVS) **Base:** `main` ← **Head:** `codex/windows-allocator-options` --- ### 📝 Commits (3) - [`93f42ea`](https://github.com/horizon-rust/horizon/commit/93f42ead5b789b34e28170153740f6d0a96072ef) Add independent opt-in Windows allocator build features - [`5a453aa`](https://github.com/horizon-rust/horizon/commit/5a453aac0f82510b4b406194df5ece67dd2c20ef) Merge main into Windows allocator options - [`ca27b2d`](https://github.com/horizon-rust/horizon/commit/ca27b2de97033203b57510a14e9811aa15d66cc9) Merge main and preserve the upstream mimalloc allocator ### 📊 Changes **5 files changed** (+100 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/Cargo.toml` (+4 -0) 📝 `crates/horizon-client/build.rs` (+7 -1) ➕ `crates/horizon-client/windows-segment-heap.manifest` (+17 -0) 📝 `docs/native-client.md` (+3 -0) ➕ `docs/windows-allocators.md` (+69 -0) </details> ### 📄 Description > 🤖 Opened by ult1mq's AI agent (Codex, GPT-6), not by ult1mq personally. ## What and why Rapid flight produced short frame-time spikes on one Windows machine. Native profiling pointed to contention in the Windows heap path. This PR adds an off-by-default `windows-segment-heap` Cargo feature so maintainers can measure the Win32 heap choice on the current client. Main has since merged [#4160](https://github.com/horizon-rust/horizon/pull/4160), which already makes mimalloc the game's global allocator. This PR preserves `horizon_threads::Allocator`, its startup configuration, memory-release behavior, and dependencies exactly as they are on main. The earlier `windows-mimalloc` feature name remains accepted as a documented compatibility no-op; it adds no dependency and does not select a second allocator. `windows-segment-heap` embeds a manifest through the existing Windows-host `winresource` step, alongside the unchanged icon and version resources. It requests `asInvoker`, without elevation, and affects Win32 heap APIs that native libraries can still use alongside mimalloc. Non-Windows builds retain main's behavior. Cross-compiling these resources from a non-Windows host is not supported by the existing build step. No world streaming, meshing, rendering or gameplay code is changed. The [Windows allocator experiment guide](https://github.com/ult1mq/horizon/blob/codex/windows-allocator-options/docs/windows-allocators.md) describes the current mimalloc baseline, the Segment Heap build, final-PE manifest inspection and controlled measurements. Changing the heap option requires rebuilding and restarting; it is not a runtime switch or mod. Segment Heap support starts at Windows 10 version 2004/build 19041, per [Microsoft's manifest specification](https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests#heaptype). Fixes #4042 ## Kind - [ ] parity: Horizon now does what vanilla 26.3 does - [ ] bug: a crash or a breakage - [ ] perf: faster, or less memory - [ ] feature: something new for players (listed under New in the release notes) - [x] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference Horizon-only native allocation/build configuration. No vanilla gameplay behavior is changed. ## Evidence and limits The motivating measurements used the **older nightly `baa379d71777f06a95b4e7650b2209a3d4209033`**, not the current mimalloc-based PR base `8f376a471`. They compare the stock executable with a candidate whose only intentional change was the embedded Segment Heap manifest. A PE comparison verified unchanged non-resource sections and preserved original icon/version resources. This supports trying Segment Heap on that machine; it is not a benchmark of this source integration or evidence of a benefit on the current mimalloc-based client. | Historical variant | Frames / measured seconds | Average FPS | p99 frame time | Maximum frame time | | --- | ---: | ---: | ---: | ---: | | Stock nightly | 3,027 / 31.99 s | 94.63 | 36.59 ms | 54.67 ms | | Same nightly, Segment Heap manifest only | 4,432 / 32.02 s | 138.43 | 10.78 ms | 29.57 ms | ![Historical SegmentHeap manifest-only measurements](https://raw.githubusercontent.com/ult1mq/horizon/252001fe34c5a77536886617b2e8f136ab8aee6a/reports/2026-10-flight/segmentheap-frame-times.png) [Sanitized timing arrays, plotting script, reproduction protocol and limitations](https://github.com/ult1mq/horizon/tree/252001fe34c5a77536886617b2e8f136ab8aee6a/reports/2026-10-flight). Hardware: Intel Core i9-13900K, NVIDIA RTX 3090, 2560×1440, Vulkan, Windows 11 build 26200. Each variant used a fresh copy of the same world, warmed at render distance 64 for 20 seconds, returned to render distance 16/simulation distance 9/LOD distance 64 with full LOD, waited 12 seconds, then made four 256-block flights lasting eight seconds each. Game FPS limit: 160. The display is 165 Hz; a later read-only NVAPI inspection found a global driver VSync override enabled even though game VSync was off. These are whole-system frame times under those caps, not uncapped throughput. One machine and one sequential session per variant are insufficient for a general performance claim. Four flight passes are not four independent trials. Load order, world scheduling, driver behavior and run-to-run variance remain limitations. The raw per-pass values are included with the graph/evidence attachment. **There is no isolated mimalloc measurement.** A later custom build combined mimalloc, Segment Heap, mesh buffer reuse and LOD retirement changes. Its results cannot establish mimalloc's contribution or be attributed to this PR. Likewise, the later 165 FPS result was display/driver capped and used a different warm-up period; it does not establish this PR's maximum FPS. Segment Heap remains off by default. New controlled measurements must compare current main's mimalloc baseline against that same client plus Segment Heap. The legacy `windows-mimalloc` feature cannot measure system allocation versus mimalloc. Broader Windows/hardware results are still needed; no new performance measurement is claimed for this merge. ## Self-check [Merged current main](https://github.com/ult1mq/horizon/commit/ca27b2de97033203b57510a14e9811aa15d66cc9) (`8f376a471237775e521e910a834a552244e12207`) into the existing PR branch with both parents preserved. No rebase or force push. The conflicts in `Cargo.lock` and client `main.rs` were resolved by taking current main unchanged. The PR now changes five files, +100/-1: Cargo feature declarations, the resource build step, the manifest, the experiment guide, and its existing native-client guide link. It makes no lockfile or allocator implementation changes relative to main. An independent review of the resolution found no actionable issues. **pr_ready** (`tools/pr_ready.py --quick` on local Windows (host name redacted), against origin/main at 8f376a471, 2 min 52 s) | Check | Result | | --- | --- | | Scope | ✅ 5 files, +100 −1 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ❌ 481 run, FAILED (failures=1, skipped=11) (39 s) | | rustfmt | ✅ (6 s) | | clippy | ✅ (38 s) | | tests: horizon-client | ❌ 781 passed, 1 failed (1 min 24 s) | | doc tests | ✅ 0 passed (1 s) | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ not run (--quick): CI's parity job picks the affected harnesses | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | All four retained Windows MSVC command combinations passed `cargo check --locked -p horizon-client --bin horizon-client`: baseline, `windows-segment-heap`, compatibility `windows-mimalloc`, and both. The latter two do not introduce another allocator variant. These checks execute the resource build step and type-check the client; they do not link or launch a full game. The actual resolved `build.rs` was also compiled and exercised with two linked minimal Windows PE probes. `mt.exe` extracted and validated manifest resource #1; the SegmentHeap namespace/value and `asInvoker` were verified. All nine icon/group-icon/version payloads matched the baseline byte for byte. The baseline had no SegmentHeap manifest, and a Linux target emitted no Windows resource. No game was launched. The public-tree history check and PR-delta whitespace check passed. The Python suite ran 481 tests with one failure and 11 skips. Its Windows failure in `WorkspaceManifestTests.test_a_feature_of_a_workspace_crate_counts_through_its_sources` was independently reproduced with the exact focused test on untouched current main `8f376a471` in a clean detached worktree. The client library ran 781 passing tests, one failure and 20 ignored tests. `title::tests::each_world_preset_writes_its_own_generator` failed with Windows OS error 267 for a preset-ID directory containing a colon. This is the same Windows fixture failure previously reproduced on the untouched earlier base; the fixture is identical to current main, but a separate current-main Rust baseline run was not performed. Library failure stops subsequent binary/integration test targets, so those are not claimed as tested. [Earlier untouched-base Windows failures](https://github.com/ult1mq/horizon/blob/f14e99548a7a70ac83fdbdaa59b70d4ec84f87b7/reports/2026-10-flight/checks/baseline-checks.txt). No unrelated fixture changes are included in this PR. Vanilla parity harnesses were not run locally (`--quick`); the self-check lists their scope. The historical graph above is separate from validation of this updated merge. 🤖 Generated with [Codex](https://openai.com/codex/). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:12:15 +07:00
Sign in to join this conversation.
No milestone
No project
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.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#5388
No description provided.