[PR #7409] [MERGED] Skip two per-frame block entity scans that find nothing #7586

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7409
Author: @ludovic111
Created: 11/2/2026
Status: ✅ Merged
Merged: 11/2/2026
Merged by: @ludovic111

Base: main ← Head: perf/block-entity-scans


📝 Commits (1)

  • d1ebc01 Skip two per-frame block entity scans that find nothing

📊 Changes

2 files changed (+15 additions, -5 deletions)

View changed files

📝 crates/horizon-client-render/src/gfx.rs (+3 -1)
📝 crates/horizon-client/src/game.rs (+12 -4)

📄 Description

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

Two block-entity scans ran every frame and found nothing in most worlds. I found them profiling the village flight at RD 32: entity_geometry takes about 11 % of the main thread there, and these scans are part of it.

  • Mod block entity pass. It walked every loaded block entity, in every resident section and at any distance, asking each whether a vanilla renderer draws it, to find the mods' among them. Every furnace, hopper, barrel, dispenser and other unrendered block entity went through it, even in a world with no mod block entity at all. It now runs only when the world holds one: BlockEntities::has_mods, the same index that mods_near and level access already rely on. Without any, it had nothing to find, since mod_block_entity_geometry draws only BlockEntity::Mod entries. Its kept.sweep still runs.
  • visible_block_entities_in_frustum. It looked up each section's upload time and computed its age on every frame, even with no section fading in. It now uses the shortcut visible_block_entities already has: when no section was uploaded within the fade, every section is whole (chunk_visibility is 1 for any age ≥ the fade, and for a fade of 0).

Both are exact by construction: the same block entities are drawn, in the same order.

Measured

sample of the main thread during the village flight: RD 32, Mac mini M4 Pro, 1280×720 offscreen, 14 s. Base 5914e52b92 (this PR's parent).

base this PR
mod block entity scan (Renderer::visible_block_entities under entity_geometry) 6 samples (0.38 % of the main thread) 0
section-age lookups for the frustum scan present gone when no section is fading in (while flying at RD 32, new sections fade in almost all the time, so this half mostly helps a player standing still)

The gain is small in this village. The mod scan's cost grows with every loaded block entity, so bases full of hoppers, furnaces and chests at a high render distance pay most. The Mac was under memory pressure during these runs, so I did not take an fps A/B; the profile counts are the measurement.

Checks (playhorizon, head ed3a9e380; the head only rewords the commit)

cargo fmt --all -- --check                                              ok
cargo clippy --profile fast -p horizon-client -p horizon-client-lib -p horizon-client-render --lib --bins --tests -- -D warnings   ok, 0 diagnostics
cargo test -p horizon-client-render --lib block_entit                   43 passed (1 ignored)
cargo test -p horizon-client --lib native_block_entity                  6 passed

🤖 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/7409 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/block-entity-scans` --- ### 📝 Commits (1) - [`d1ebc01`](https://github.com/horizon-rust/horizon/commit/d1ebc018279c6a9332a2c079a26eefb2599f400a) Skip two per-frame block entity scans that find nothing ### 📊 Changes **2 files changed** (+15 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/gfx.rs` (+3 -1) 📝 `crates/horizon-client/src/game.rs` (+12 -4) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Two block-entity scans ran every frame and found nothing in most worlds. I found them profiling the `village` flight at RD 32: `entity_geometry` takes about 11 % of the main thread there, and these scans are part of it. - **Mod block entity pass.** It walked every loaded block entity, in every resident section and at any distance, asking each whether a vanilla renderer draws it, to find the mods' among them. Every furnace, hopper, barrel, dispenser and other unrendered block entity went through it, even in a world with no mod block entity at all. It now runs only when the world holds one: `BlockEntities::has_mods`, the same index that `mods_near` and level access already rely on. Without any, it had nothing to find, since `mod_block_entity_geometry` draws only `BlockEntity::Mod` entries. Its `kept.sweep` still runs. - **`visible_block_entities_in_frustum`.** It looked up each section's upload time and computed its age on every frame, even with no section fading in. It now uses the shortcut `visible_block_entities` already has: when no section was uploaded within the fade, every section is whole (`chunk_visibility` is 1 for any age ≥ the fade, and for a fade of 0). Both are exact by construction: the same block entities are drawn, in the same order. ### Measured `sample` of the main thread during the `village` flight: RD 32, Mac mini M4 Pro, 1280×720 offscreen, 14 s. Base `5914e52b92` (this PR's parent). | | base | this PR | |---|---|---| | mod block entity scan (`Renderer::visible_block_entities` under `entity_geometry`) | 6 samples (0.38 % of the main thread) | 0 | | section-age lookups for the frustum scan | present | gone when no section is fading in (while flying at RD 32, new sections fade in almost all the time, so this half mostly helps a player standing still) | The gain is small in this village. The mod scan's cost grows with every loaded block entity, so bases full of hoppers, furnaces and chests at a high render distance pay most. The Mac was under memory pressure during these runs, so I did not take an fps A/B; the profile counts are the measurement. ### Checks (playhorizon, head ed3a9e380; the head only rewords the commit) ``` cargo fmt --all -- --check ok cargo clippy --profile fast -p horizon-client -p horizon-client-lib -p horizon-client-render --lib --bins --tests -- -D warnings ok, 0 diagnostics cargo test -p horizon-client-render --lib block_entit 43 passed (1 ignored) cargo test -p horizon-client --lib native_block_entity 6 passed ``` 🤖 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-03 07:20:19 +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#7586
No description provided.