[PR #3284] [MERGED] Signs: keep laid-out sign text between frames (3458 signs: 124 → 222 fps) #4891

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

📋 Pull Request Information

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

Base: main ← Head: perf/sign-text-cache


📝 Commits (1)

  • 0281365 Signs: keep laid-out sign text between frames, batch entity quads in runs

📊 Changes

6 files changed (+295 additions, -57 deletions)

View changed files

📝 crates/horizon-client/examples/probe/block_entity_render_fixture.rs (+1 -0)
📝 crates/horizon-client/src/block_entity_render.rs (+235 -8)
📝 crates/horizon-client/src/font.rs (+15 -0)
📝 crates/horizon-client/src/game.rs (+1 -0)
📝 crates/horizon-client/src/game/minecarts.rs (+1 -0)
📝 crates/horizon-client/src/gfx/entity_batch.rs (+42 -49)

📄 Description

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

Fixes #1461.

What was slow

Each frame, every sign in view laid its text out again one glyph at a time: line fitting, width, glyph lookup and quad emission, repeated for every outline pass of glowing text. On a 14×19×13 cube of 3458 four-line signs (the reporter's scene), Font::glyph_of alone took a quarter of the main thread. Then EntityBatch::update grouped every entity quad by material through a per-quad index list and copied the quads one at a time (another fifth).

Fix

  • Sign text cache (block_entity_render.rs). Each sign's text vertices are kept relative to its block, and each frame they are only copied with the camera offset. The text is laid out again when anything that shapes it changes: the sign data, the block state, the light at the sign, being within 16 blocks of glowing text (the outline, isOutlineVisible), or the font. The font check uses the new Font::epoch, which changes with a new font, a glyph-cache reset, or the Force Unicode and Japanese glyph options. Signs that go unused for 100 ticks are dropped. The parity fixture's path (Scene::texts, render_block) is not changed.
  • Entity batch in runs (gfx/entity_batch.rs). Consecutive quads that share a material form one run, and whole runs are copied. The existing equivalence test against the original implementation still passes. Microbenchmark (benchmark_entity_batch), before → after:
    • single material, 262k quads: 3.9 → 2.1 ms
    • model-like runs, 65k quads: 622 → 312 µs
    • every quad a different material (the worst case): about the same

The look and the text distance are unchanged: text is still drawn to the 64-block view distance, the same as vanilla. A pixel diff of the cube region before and after shows 6 of 268,800 pixels differing, fewer than two runs of the old build differ from each other (24).

Numbers

Mac mini M4 Pro, --profile fast, offscreen 1280×720, uncapped (maxFps:260, inactivityFpsLimit:"minimized"), horizon-ctl bench 15, same seed, spot and view. The three builds ran back to back:

3458 text signs in view fps CPU ms/frame prepare render GPU ms
main (cba52f4e5) 124 8.01 5.17 2.80 2.52
+ sign text cache 191 5.20 2.36 2.81 1.95
+ entity batch runs (this PR) 222 4.46 2.66 1.76 1.57

The same view without signs runs at about 1620 fps on every build. On an idle machine, main ran 128 fps with signs and 1642 without.

The remaining cost is the volume of text vertices: about 550k vertices per frame, about 24 MB streamed to the GPU. Removing it would mean keeping the text resident on the GPU, which needs changes in every pass that draws entities, including shader packs; that is a separate change.

Tests

  • block_entity_render::tests::cached_sign_text_matches_and_follows_changes: the cached output matches the uncached renderer after a camera move, new text, glowing text near and far, another sign state, another position and different glyphs. Unused signs are dropped.
  • gfx::entity_batch::tests::stable_material_order_tails_and_reuse still passes, comparing against the original implementation.

Self-check (python3 tools/pr_ready.py, Mac mini, against origin/main)

Public tree:   pass (0 s)
Python tests:  pass (1 min 13 s)
Parity:        pass (105 min 40 s), the 50 harnesses `tools/parity.py --changed origin/main` picks
rustfmt:       pass (12 s)
clippy:        pass (7 min 55 s), -D warnings
tests:         horizon-client: pass, run directly with `cargo test -p horizon-client --lib --bins --tests`:
               1101 lib + 132 bin + 28 integration (0 failed). pr_ready reached its 2 h limit on this last
               step on a loaded machine, so it printed no block.
entity_batch:  `benchmark_entity_batch` (ignored microbenchmark) run with --profile fast, numbers above

🤖 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/3284 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/28/2026 **Status:** ✅ Merged **Merged:** 10/28/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/sign-text-cache` --- ### 📝 Commits (1) - [`0281365`](https://github.com/horizon-rust/horizon/commit/0281365907e0d71346101b2734bbc28c11046b3e) Signs: keep laid-out sign text between frames, batch entity quads in runs ### 📊 Changes **6 files changed** (+295 additions, -57 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/examples/probe/block_entity_render_fixture.rs` (+1 -0) 📝 `crates/horizon-client/src/block_entity_render.rs` (+235 -8) 📝 `crates/horizon-client/src/font.rs` (+15 -0) 📝 `crates/horizon-client/src/game.rs` (+1 -0) 📝 `crates/horizon-client/src/game/minecarts.rs` (+1 -0) 📝 `crates/horizon-client/src/gfx/entity_batch.rs` (+42 -49) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Fixes #1461. ## What was slow Each frame, every sign in view laid its text out again one glyph at a time: line fitting, width, glyph lookup and quad emission, repeated for every outline pass of glowing text. On a 14×19×13 cube of 3458 four-line signs (the reporter's scene), `Font::glyph_of` alone took a quarter of the main thread. Then `EntityBatch::update` grouped every entity quad by material through a per-quad index list and copied the quads one at a time (another fifth). ## Fix - **Sign text cache** (`block_entity_render.rs`). Each sign's text vertices are kept relative to its block, and each frame they are only copied with the camera offset. The text is laid out again when anything that shapes it changes: the sign data, the block state, the light at the sign, being within 16 blocks of glowing text (the outline, `isOutlineVisible`), or the font. The font check uses the new `Font::epoch`, which changes with a new font, a glyph-cache reset, or the Force Unicode and Japanese glyph options. Signs that go unused for 100 ticks are dropped. The parity fixture's path (`Scene::texts`, `render_block`) is not changed. - **Entity batch in runs** (`gfx/entity_batch.rs`). Consecutive quads that share a material form one run, and whole runs are copied. The existing equivalence test against the original implementation still passes. Microbenchmark (`benchmark_entity_batch`), before → after: - single material, 262k quads: 3.9 → 2.1 ms - model-like runs, 65k quads: 622 → 312 µs - every quad a different material (the worst case): about the same The look and the text distance are unchanged: text is still drawn to the 64-block view distance, the same as vanilla. A pixel diff of the cube region before and after shows 6 of 268,800 pixels differing, fewer than two runs of the old build differ from each other (24). ## Numbers Mac mini M4 Pro, `--profile fast`, offscreen 1280×720, uncapped (`maxFps:260`, `inactivityFpsLimit:"minimized"`), `horizon-ctl bench 15`, same seed, spot and view. The three builds ran back to back: | 3458 text signs in view | fps | CPU ms/frame | prepare | render | GPU ms | |---|---|---|---|---|---| | main (cba52f4e5) | 124 | 8.01 | 5.17 | 2.80 | 2.52 | | + sign text cache | 191 | 5.20 | 2.36 | 2.81 | 1.95 | | + entity batch runs (this PR) | **222** | **4.46** | 2.66 | 1.76 | 1.57 | The same view without signs runs at about 1620 fps on every build. On an idle machine, main ran 128 fps with signs and 1642 without. The remaining cost is the volume of text vertices: about 550k vertices per frame, about 24 MB streamed to the GPU. Removing it would mean keeping the text resident on the GPU, which needs changes in every pass that draws entities, including shader packs; that is a separate change. ## Tests - `block_entity_render::tests::cached_sign_text_matches_and_follows_changes`: the cached output matches the uncached renderer after a camera move, new text, glowing text near and far, another sign state, another position and different glyphs. Unused signs are dropped. - `gfx::entity_batch::tests::stable_material_order_tails_and_reuse` still passes, comparing against the original implementation. ## Self-check (`python3 tools/pr_ready.py`, Mac mini, against origin/main) ``` Public tree: pass (0 s) Python tests: pass (1 min 13 s) Parity: pass (105 min 40 s), the 50 harnesses `tools/parity.py --changed origin/main` picks rustfmt: pass (12 s) clippy: pass (7 min 55 s), -D warnings tests: horizon-client: pass, run directly with `cargo test -p horizon-client --lib --bins --tests`: 1101 lib + 132 bin + 28 integration (0 failed). pr_ready reached its 2 h limit on this last step on a loaded machine, so it printed no block. entity_batch: `benchmark_entity_batch` (ignored microbenchmark) run with --profile fast, numbers above ``` 🤖 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 05:08:41 +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#4891
No description provided.