[PR #735] [MERGED] Cull minecarts by distance and view like vanilla #2766

Closed
opened 2026-11-02 15:58:53 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/735
Author: @ludovic111
Created: 10/17/2026
Status: ✅ Merged
Merged: 10/17/2026
Merged by: @ludovic111

Base: main ← Head: fix/minecart-render-culling


📝 Commits (1)

  • 1c2f766 Cull minecarts by distance and view like vanilla

📊 Changes

1 file changed (+40 additions, -8 deletions)

View changed files

📝 crates/horizon-client/src/game/minecarts.rs (+40 -8)

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

Part of the frame-time work on large render distances (the entity geometry spikes seen next to #678).

Cause

cart_geometry drew every loaded minecart every frame, wherever it was: no render-distance check and no view check. At render distance 32 that is every chest minecart of every loaded mineshaft, each going through three rail lookups, the display block (a BlockState clone and registry hash), the model, and the per-vertex terrain occlusion test, only for the GPU to clip it. Mobs, by contrast, were already culled as in vanilla.

Fix

The vanilla rules, from LevelExtractor.isEntityVisible and EntityRenderer.shouldRender:

  • distance: Entity.shouldRenderAtSqrDistance, 64 times the bounding box's mean edge (0.98, 0.7, 0.98: about 57 blocks at entity distance 100%), measured from the cart's current position, scaled by the entity distance option;
  • view: the interpolated bounding box grown by 0.5, stretched up by the display block's offset for carts that carry a block (AbstractMinecartRenderer.getBoundingBoxForCulling; offset 6, or 1 for hopper minecarts);
  • the cart the player rides always draws (hasIndirectPassenger).

The minecart sprite lookup also moved out of the per-cart loop.

Picture

Five fixed views, the same save, chest and plain minecarts summoned 8, 40 and 80 blocks north and 8 blocks south, tick frozen, GUI hidden. I compared origin/main (base, run twice) with this branch, keeping only pixels where both base runs agree and the new one differs by more than 24 per channel:

View What differs
north, carts ahead the two carts 80 blocks away are not drawn (vanilla does not draw them either, beyond 57 blocks); the carts at 8 and 40 blocks are identical
north, looking down same
south, cart 8 blocks away identical carts; mobs that wandered before the freeze differ from run to run
215°, carts at the edge of the view the far carts only
east, no cart in view identical (one wandering mob)

The sky and vignette brightness drift by a few levels between any two runs of the same binary (base vs base too), so I compared with that tolerance.

Performance

Mac mini M4 Pro (Metal), offscreen 1280×720, the bench save at (-524.5, 90, 74.5), spectator, turning 360° in 10 s per run. One fresh game per run, alternating base/new. The machine was heavily loaded by other sessions (load average 45–113, ~/fleet/load busy), so FPS and lows are noisy; the entity geometry figures are the direct measure. Entity geometry comes from HORIZON_SPIKES=0 spans, which list spans of 0.5 ms or more, so its mean counts shorter frames as 0 (a lower bound on base's cost).

RD 32, 4 pairs:

base this PR PR better in
avg FPS 86.5 119.7 3/4
1% low FPS 5.6 7.2 3/4
0.1% low FPS 4.1 4.9 3/4
frame p99 (ms) 168.6 113.4 3/4
CPU ms/frame 9.0 6.2 2/4
prepare phase ms/frame 1.50 0.69 4/4
frames with entity geometry ≥ 0.5 ms 12.4% 2.8% 4/4
entity geometry mean (ms, ≥ 0.5 only) 0.68 0.07 4/4
entity geometry max (ms) 105 34 3/4

RD 16, 3 pairs:

base this PR PR better in
avg FPS 113.7 152.0 1/3
1% low FPS 3.8 5.7 2/3
0.1% low FPS 2.8 3.6 2/3
frame p99 (ms) 218.1 126.3 3/3
CPU ms/frame 7.3 5.3 1/3
prepare phase ms/frame 1.35 0.78 2/3
frames with entity geometry ≥ 0.5 ms 4.3% 1.7% 3/3

GPU time is not reported: origin/main has no GPU timer on Apple GPUs. The FPS and lows move with the load more than with this change; the per-frame entity geometry cost and the prepare phase are what this PR changes, and they drop in every pair at RD 32.

Checks

  • cargo fmt --all --check, cargo clippy --workspace --all-targets -- -D warnings, cargo test -p horizon-client --lib (823 passed): pass.
  • Local parity (tools/parity.py --changed origin/main): 15 passed, 0 failed (every harness that depends on the changed file).

Not in this PR: hopper minecarts draw their hopper at display offset 6 instead of vanilla's 1 (about 0.23 blocks too high); boats, paintings, item frames, armor stands, primed TNT, tridents, fireworks and fishing bobbers also appear to have no distance or view culling yet (follow-ups).

🤖 Generated with Claude Code


🔄 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/735 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/17/2026 **Status:** ✅ Merged **Merged:** 10/17/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/minecart-render-culling` --- ### 📝 Commits (1) - [`1c2f766`](https://github.com/horizon-rust/horizon/commit/1c2f7664c3d1b23918b894699a77df303d4d1c5f) Cull minecarts by distance and view like vanilla ### 📊 Changes **1 file changed** (+40 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/minecarts.rs` (+40 -8) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Part of the frame-time work on large render distances (the entity geometry spikes seen next to #678). ## Cause `cart_geometry` drew every loaded minecart every frame, wherever it was: no render-distance check and no view check. At render distance 32 that is every chest minecart of every loaded mineshaft, each going through three rail lookups, the display block (a `BlockState` clone and registry hash), the model, and the per-vertex terrain occlusion test, only for the GPU to clip it. Mobs, by contrast, were already culled as in vanilla. ## Fix The vanilla rules, from `LevelExtractor.isEntityVisible` and `EntityRenderer.shouldRender`: - distance: `Entity.shouldRenderAtSqrDistance`, 64 times the bounding box's mean edge (0.98, 0.7, 0.98: about 57 blocks at entity distance 100%), measured from the cart's current position, scaled by the entity distance option; - view: the interpolated bounding box grown by 0.5, stretched up by the display block's offset for carts that carry a block (`AbstractMinecartRenderer.getBoundingBoxForCulling`; offset 6, or 1 for hopper minecarts); - the cart the player rides always draws (`hasIndirectPassenger`). The minecart sprite lookup also moved out of the per-cart loop. ## Picture Five fixed views, the same save, chest and plain minecarts summoned 8, 40 and 80 blocks north and 8 blocks south, tick frozen, GUI hidden. I compared origin/main (base, run twice) with this branch, keeping only pixels where both base runs agree and the new one differs by more than 24 per channel: | View | What differs | | --- | --- | | north, carts ahead | the two carts 80 blocks away are not drawn (vanilla does not draw them either, beyond 57 blocks); the carts at 8 and 40 blocks are identical | | north, looking down | same | | south, cart 8 blocks away | identical carts; mobs that wandered before the freeze differ from run to run | | 215°, carts at the edge of the view | the far carts only | | east, no cart in view | identical (one wandering mob) | The sky and vignette brightness drift by a few levels between any two runs of the same binary (base vs base too), so I compared with that tolerance. ## Performance Mac mini M4 Pro (Metal), offscreen 1280×720, the bench save at (-524.5, 90, 74.5), spectator, turning 360° in 10 s per run. One fresh game per run, alternating base/new. The machine was heavily loaded by other sessions (load average 45–113, `~/fleet/load` busy), so FPS and lows are noisy; the entity geometry figures are the direct measure. Entity geometry comes from `HORIZON_SPIKES=0` spans, which list spans of 0.5 ms or more, so its mean counts shorter frames as 0 (a lower bound on base's cost). RD 32, 4 pairs: | | base | this PR | PR better in | | --- | --- | --- | --- | | avg FPS | 86.5 | 119.7 | 3/4 | | 1% low FPS | 5.6 | 7.2 | 3/4 | | 0.1% low FPS | 4.1 | 4.9 | 3/4 | | frame p99 (ms) | 168.6 | 113.4 | 3/4 | | CPU ms/frame | 9.0 | 6.2 | 2/4 | | prepare phase ms/frame | 1.50 | 0.69 | 4/4 | | frames with entity geometry ≥ 0.5 ms | 12.4% | 2.8% | 4/4 | | entity geometry mean (ms, ≥ 0.5 only) | 0.68 | 0.07 | 4/4 | | entity geometry max (ms) | 105 | 34 | 3/4 | RD 16, 3 pairs: | | base | this PR | PR better in | | --- | --- | --- | --- | | avg FPS | 113.7 | 152.0 | 1/3 | | 1% low FPS | 3.8 | 5.7 | 2/3 | | 0.1% low FPS | 2.8 | 3.6 | 2/3 | | frame p99 (ms) | 218.1 | 126.3 | 3/3 | | CPU ms/frame | 7.3 | 5.3 | 1/3 | | prepare phase ms/frame | 1.35 | 0.78 | 2/3 | | frames with entity geometry ≥ 0.5 ms | 4.3% | 1.7% | 3/3 | GPU time is not reported: origin/main has no GPU timer on Apple GPUs. The FPS and lows move with the load more than with this change; the per-frame entity geometry cost and the prepare phase are what this PR changes, and they drop in every pair at RD 32. ## Checks - `cargo fmt --all --check`, `cargo clippy --workspace --all-targets -- -D warnings`, `cargo test -p horizon-client --lib` (823 passed): pass. - Local parity (`tools/parity.py --changed origin/main`): 15 passed, 0 failed (every harness that depends on the changed file). Not in this PR: hopper minecarts draw their hopper at display offset 6 instead of vanilla's 1 (about 0.23 blocks too high); boats, paintings, item frames, armor stands, primed TNT, tridents, fireworks and fishing bobbers also appear to have no distance or view culling yet (follow-ups). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 15:58:53 +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#2766
No description provided.