[PR #4050] [MERGED] Reuse worker meshing scratch and bounded mesh capacity #5380

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

📋 Pull Request Information

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

Base: main ← Head: codex/mesh-buffer-reuse


📝 Commits (3)

  • 3813fba Reuse worker meshing scratch and bounded mesh capacity
  • 5f72e12 Merge main into mesh buffer reuse
  • 43e29d4 Merge main into codex/mesh-buffer-reuse

📊 Changes

4 files changed (+401 additions, -15 deletions)

View changed files

📝 crates/horizon-client-render/src/mesher.rs (+64 -11)
➕ crates/horizon-client-render/src/mesher/reuse_tests.rs (+208 -0)
📝 crates/horizon-client-render/src/mesher/visibility_tests.rs (+15 -0)
📝 crates/horizon-client-render/src/streaming.rs (+114 -4)

📄 Description

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

What and why

Non-empty section jobs currently allocate their padded block/light arrays and unpack buffer afresh; uploaded CPU geometry is subsequently freed. During fast flight, repeated mesh creation and disposal adds allocator traffic while other workers and the frame thread share the process allocator.

Keep a lazily initialized MeshScratch per streaming worker and recycle uploaded SectionMesh vector capacity through a worker-only pool. The pool retains at most 128 meshes and 16 MiB of vector capacity in total, and rejects oversized meshes. A mesh is cleared before reuse, including visibility, solid-side buckets and block-entity candidates. Uniform-air jobs still return before allocating scratch storage. Retained buffers also follow main's five-second idle release policy: each idle worker drops its scratch, and the last idle worker drains the mesh pool outside its lock before returning free memory to the OS. Scratch contains only block/light values and indices, so a resource-pack reload cannot leave model references in it.

This is an independent allocation-reuse change. It leaves job priorities, in-flight limits, LOD ownership and the allocator configuration unchanged. It can be reviewed independently of #3961, which changes streaming scheduling.

Fixes #4041

Evidence and limits

The isolated opt-in microbenchmark compares fresh and retained padding buffers using identical chunk reads. Both paths use this branch's fill implementation; this is not an origin/main A/B test. It prints every sample, alternates execution order and checks retained buffer addresses. It measures only the padding stage; it does not measure whole-frame latency or assert an FPS improvement. The retained fixed scratch arrays total 56,384 bytes per initialized worker on this target; the visibility stack is additional and bounded by the 4,096 section cells.

On Windows with the optimized fast profile, after 1,024 warmup fills per path, nine samples of 4,096 fills each gave:

Current padding path Median µs/fill Observed range, µs/fill
Fresh scratch 11.181 10.962–13.852
Retained scratch 10.505 10.203–10.953

These historical padding samples were collected on original PR head 3813fba81, before this merge of main. No new runtime benchmark was performed for conflict resolution. The observed median is 6.0% lower for retained scratch. This is a descriptive result from one local run, with no significance claim. The fresh wrapper initializes newly allocated storage before fill clears it, so these numbers must not be read as the prepatch implementation's speedup.

Isolated padding observations

Raw samples, portable plotting script and exact reproduction commands.

The earlier Windows flight investigation found the frame thread waiting in heap routines in 112/242 outbound native samples (46.3%). That diagnosis motivated reducing allocator traffic. The earlier FPS/frame-time improvements came from a combined experimental build that also changed scheduling, LOD replacement and allocator settings. Those results cannot establish this PR's independent benefit. A later 165 FPS plateau also coincided with a driver-enforced VSync setting on a 165 Hz display.

Correctness coverage

  • Padded block/light reuse is compared against direct Chunk reads, including missing neighbors and transitions back to populated data.
  • Visibility reuse is compared with the independent flood-fill reference on the existing adversarial fixtures, including shortcut paths and poisoned scratch contents.
  • Pool tests verify reset state, retained addresses/capacity, count limits, aggregate byte limits, oversized rejection and accounting after draining.
  • An explicit asset-backed test compares complete vertex bytes, block entities, visibility and side buckets between fresh and reused meshes across dense, sparse and empty sections, changed neighbors, graphics options and resource reload. It is ignored by default because it requires prepared Minecraft resources; it fails rather than silently skipping when explicitly invoked without them.

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

No vanilla rendering behavior changes. Existing ModelBlockRenderer/BlockModelLighter, FluidRenderer and VisGraph.resolve behavior is preserved; this changes the lifetime of Horizon's temporary storage. The existing meshing/visibility checks and affected parity harnesses remain the behavior gates.

Self-check

Merged current main (e84a47c06994b7b7516145d5f3b83d19644dcbe2) into the existing PR branch, preserving both parents and its original history.

The mesher/streamer conflicts were resolved by keeping main's layout-relative section coordinates (Chunk::min_y) and its five-second worker idle-memory release, together with the PR's bounded pool and reusable scratch. Regression coverage now exercises section 1 at four valid world minimum heights and checks block-entity world coordinates in a custom-height column. The PR delta remains limited to the same four meshing/streaming files.

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

Check Result
Scope ✅ 4 files, +393 −15
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ❌ 480 run, FAILED (failures=1, skipped=11) (40 s)
rustfmt ✅ (6 s)
clippy ✅ (31 s)
tests: horizon-client-render ✅ 577 passed (45 s)
doc tests ✅ 0 passed (11 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)

The explicit ignored reused_mesh_matches_fresh_geometry_across_sections_and_resource_reload test passed with prepared 26.3 resources, including the new custom-height chest fixture. It compares complete solid/translucent vertex bytes, block entities, visibility and side buckets across reuse, changed neighbors/options and resource reload. The new layout/reset regression and pool/visibility tests are included in the rendering-library self-check above.

The Python suite still has the documented Windows failure in WorkspaceManifestTests.test_a_feature_of_a_workspace_crate_counts_through_its_sources. It was independently reproduced on untouched earlier base bd665f28a, and its test and runner files are unchanged in the merged main. No unrelated test fix is included in this PR.

Documented untouched-base Windows failures. Vanilla parity harnesses were not run locally (--quick); the table lists their scope. The historical measurements in the evidence section are 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/4050 **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/mesh-buffer-reuse` --- ### 📝 Commits (3) - [`3813fba`](https://github.com/horizon-rust/horizon/commit/3813fba81c2d5d3ebc69bf3b32a2e28c20b28342) Reuse worker meshing scratch and bounded mesh capacity - [`5f72e12`](https://github.com/horizon-rust/horizon/commit/5f72e129b2b32843927317eb28e9e58fc6f418ef) Merge main into mesh buffer reuse - [`43e29d4`](https://github.com/horizon-rust/horizon/commit/43e29d4556d9e7589b27fcfe56d1c7ddf3c248b6) Merge main into codex/mesh-buffer-reuse ### 📊 Changes **4 files changed** (+401 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/mesher.rs` (+64 -11) ➕ `crates/horizon-client-render/src/mesher/reuse_tests.rs` (+208 -0) 📝 `crates/horizon-client-render/src/mesher/visibility_tests.rs` (+15 -0) 📝 `crates/horizon-client-render/src/streaming.rs` (+114 -4) </details> ### 📄 Description > 🤖 Opened by ult1mq's AI agent (Codex, GPT-6), not by ult1mq personally. ## What and why Non-empty section jobs currently allocate their padded block/light arrays and unpack buffer afresh; uploaded CPU geometry is subsequently freed. During fast flight, repeated mesh creation and disposal adds allocator traffic while other workers and the frame thread share the process allocator. Keep a lazily initialized `MeshScratch` per streaming worker and recycle uploaded `SectionMesh` vector capacity through a worker-only pool. The pool retains at most 128 meshes and 16 MiB of vector capacity in total, and rejects oversized meshes. A mesh is cleared before reuse, including visibility, solid-side buckets and block-entity candidates. Uniform-air jobs still return before allocating scratch storage. Retained buffers also follow main's five-second idle release policy: each idle worker drops its scratch, and the last idle worker drains the mesh pool outside its lock before returning free memory to the OS. Scratch contains only block/light values and indices, so a resource-pack reload cannot leave model references in it. This is an independent allocation-reuse change. It leaves job priorities, in-flight limits, LOD ownership and the allocator configuration unchanged. It can be reviewed independently of [#3961](https://github.com/horizon-rust/horizon/pull/3961), which changes streaming scheduling. Fixes #4041 ### Evidence and limits The isolated opt-in microbenchmark compares fresh and retained padding buffers using identical chunk reads. Both paths use this branch's fill implementation; this is not an origin/main A/B test. It prints every sample, alternates execution order and checks retained buffer addresses. It measures only the padding stage; it does not measure whole-frame latency or assert an FPS improvement. The retained fixed scratch arrays total 56,384 bytes per initialized worker on this target; the visibility stack is additional and bounded by the 4,096 section cells. On Windows with the optimized `fast` profile, after 1,024 warmup fills per path, nine samples of 4,096 fills each gave: | Current padding path | Median µs/fill | Observed range, µs/fill | | --- | ---: | ---: | | Fresh scratch | 11.181 | 10.962–13.852 | | Retained scratch | 10.505 | 10.203–10.953 | These historical padding samples were collected on original PR head `3813fba81`, before this merge of main. No new runtime benchmark was performed for conflict resolution. The observed median is 6.0% lower for retained scratch. This is a descriptive result from one local run, with no significance claim. The fresh wrapper initializes newly allocated storage before `fill` clears it, so these numbers must not be read as the prepatch implementation's speedup. ![Isolated padding observations](https://raw.githubusercontent.com/ult1mq/horizon/3720e70287061ea0ebc864ba1341a3948a5e588d/reports/2026-10-flight/mesh/mesh-scratch-stage.png) [Raw samples, portable plotting script and exact reproduction commands](https://github.com/ult1mq/horizon/tree/3720e70287061ea0ebc864ba1341a3948a5e588d/reports/2026-10-flight/mesh). The [earlier Windows flight investigation](https://github.com/ult1mq/horizon/tree/252001fe34c5a77536886617b2e8f136ab8aee6a/reports/2026-10-flight) found the frame thread waiting in heap routines in 112/242 outbound native samples (46.3%). That diagnosis motivated reducing allocator traffic. The earlier FPS/frame-time improvements came from a combined experimental build that also changed scheduling, LOD replacement and allocator settings. Those results cannot establish this PR's independent benefit. A later 165 FPS plateau also coincided with a driver-enforced VSync setting on a 165 Hz display. ### Correctness coverage - Padded block/light reuse is compared against direct `Chunk` reads, including missing neighbors and transitions back to populated data. - Visibility reuse is compared with the independent flood-fill reference on the existing adversarial fixtures, including shortcut paths and poisoned scratch contents. - Pool tests verify reset state, retained addresses/capacity, count limits, aggregate byte limits, oversized rejection and accounting after draining. - An explicit asset-backed test compares complete vertex bytes, block entities, visibility and side buckets between fresh and reused meshes across dense, sparse and empty sections, changed neighbors, graphics options and resource reload. It is ignored by default because it requires prepared Minecraft resources; it fails rather than silently skipping when explicitly invoked without them. ## Kind - [ ] parity: Horizon now does what vanilla 26.3 does - [ ] bug: a crash or a breakage - [x] 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 No vanilla rendering behavior changes. Existing `ModelBlockRenderer`/`BlockModelLighter`, `FluidRenderer` and `VisGraph.resolve` behavior is preserved; this changes the lifetime of Horizon's temporary storage. The existing meshing/visibility checks and affected parity harnesses remain the behavior gates. ## Self-check [Merged current main](https://github.com/ult1mq/horizon/commit/5f72e129b2b32843927317eb28e9e58fc6f418ef) (`e84a47c06994b7b7516145d5f3b83d19644dcbe2`) into the existing PR branch, preserving both parents and its original history. The mesher/streamer conflicts were resolved by keeping main's layout-relative section coordinates (`Chunk::min_y`) and its five-second worker idle-memory release, together with the PR's bounded pool and reusable scratch. Regression coverage now exercises section 1 at four valid world minimum heights and checks block-entity world coordinates in a custom-height column. The PR delta remains limited to the same four meshing/streaming files. **pr_ready** (`tools/pr_ready.py --quick` on local Windows (host name redacted), against origin/main at e84a47c06, 2 min 16 s) | Check | Result | | --- | --- | | Scope | ✅ 4 files, +393 −15 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ❌ 480 run, FAILED (failures=1, skipped=11) (40 s) | | rustfmt | ✅ (6 s) | | clippy | ✅ (31 s) | | tests: horizon-client-render | ✅ 577 passed (45 s) | | doc tests | ✅ 0 passed (11 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) | The explicit ignored `reused_mesh_matches_fresh_geometry_across_sections_and_resource_reload` test passed with prepared 26.3 resources, including the new custom-height chest fixture. It compares complete solid/translucent vertex bytes, block entities, visibility and side buckets across reuse, changed neighbors/options and resource reload. The new layout/reset regression and pool/visibility tests are included in the rendering-library self-check above. The Python suite still has the documented Windows failure in `WorkspaceManifestTests.test_a_feature_of_a_workspace_crate_counts_through_its_sources`. It was independently reproduced on untouched earlier base `bd665f28a`, and its test and runner files are unchanged in the merged main. No unrelated test fix is included in this PR. [Documented untouched-base Windows failures](https://github.com/ult1mq/horizon/blob/f14e99548a7a70ac83fdbdaa59b70d4ec84f87b7/reports/2026-10-flight/checks/baseline-checks.txt). Vanilla parity harnesses were not run locally (`--quick`); the table lists their scope. The historical measurements in the evidence section are 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:12 +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#5380
No description provided.