[PR #6656] [MERGED] Entity models baked at startup, not on first sight (a 41 ms first-leash hitch) #7015

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

📋 Pull Request Information

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

Base: main ← Head: perf/entity-models-at-startup


📝 Commits (2)

  • 491d9f5 Entity models parsed at startup, not on first sight
  • 33e2c32 Startup test: the fixture has the models now loaded at startup

📊 Changes

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

View changed files

📝 crates/horizon-client/src/game.rs (+46 -1)
📝 crates/horizon-client/src/game/creatures.rs (+2 -16)
📝 crates/horizon-client/src/game/fangs.rs (+1 -5)
📝 crates/horizon-client/src/game/leads.rs (+3 -6)
📝 crates/horizon-client/src/game/mob_blocks.rs (+2 -9)
📝 crates/horizon-client/src/game/wind.rs (+3 -6)

📄 Description

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

What and why

Six entity models were baked the first time one of their entities came into view, on the render thread, inside entity_geometry: the leash knot, the wind charge, the shulker bullet, the wither skull, the evoker fangs and the standing banner. Each one did it through a OnceLock that parsed the whole entity-models.json document again just for its one model. The first leash knot a player sees (and the first banner, wind charge…) cost one long frame.

HORIZON_SPIKES caught it in a frame-pacing run (tools/pacing_bench.py, RD 12): 41.4 ms of render-thread CPU in one frame, all of it in the leash knot's first draw (eo_leash, a lap of entity_geometry).

The fix moves these six models to GameCpuResources, the startup worker that already parses the document once for the crystal, dragon, arrow, trident and armor stand models (EntityModels::load). The draw code reads the baked Part from Game. The models, their keys and their drawing don't change, so frames look the same.

Measured

playhorizon (8 vCPU, lavapipe software Vulkan at 320x180, load average 37–52), pacing_bench.py --distances 12 --spike-ms 8, one run each. Lavapipe makes wall time GPU noise, so this compares the render thread's own CPU time per span, which HORIZON_SPIKES logs for every slow frame:

main this PR
Worst entity_geometry frame (render-thread CPU) 41.6 ms 4.6 ms
of which an entity's first model bake (eo_leash) 41.4 ms none
Worst frame of the whole run (render-thread CPU) 48.7 ms 20.8 ms

The 4.6 ms left is mob geometry (eg_mobs), which isn't touched here.

The whole-frame figures (p50, p99, p99.9, max, lows, frames > 33 ms) on a software renderer are set by lavapipe, not by this. An A/B on a real GPU comes with the frame-pacing series. The cost removed is fixed CPU work, so it is the same order on any machine: one hitch per model type, per game.

Checks

pr_ready (tools/pr_ready.py --quick on playhorizon, against origin/main at 4bc8e359c, 9 min 4 s)

Check Result
Scope ✅ 6 files, +57 −43
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 598 passed (1 min 0 s)
rustfmt ✅ (13 s)
clippy ✅ (3 min 49 s)
tests: horizon-client ✅ 593 passed (3 min 51 s)
doc tests ✅ 0 passed (3 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 ➖ 60 affected, to run in CI (--quick): armor_stand_frost, arrow, arrow_wind_charge, blending, block_particles, block_removal, block_tint, boat_authority, boat_paddle_reset, boat_submerged, breaking_model, command_exec and 48 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

Gameplay and rendering: same models, same keys, same draw calls; startup_cpu_tests::worker_prepares_owned_models_and_inventory_before_handoff now asserts the six models are prepared on the worker.

🤖 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/6656 **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/entity-models-at-startup` --- ### 📝 Commits (2) - [`491d9f5`](https://github.com/horizon-rust/horizon/commit/491d9f5e25f48a986fbec8c56365c22aaac704c4) Entity models parsed at startup, not on first sight - [`33e2c32`](https://github.com/horizon-rust/horizon/commit/33e2c32d354dd5c561904a06c1488e893eca5059) Startup test: the fixture has the models now loaded at startup ### 📊 Changes **6 files changed** (+57 additions, -43 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+46 -1) 📝 `crates/horizon-client/src/game/creatures.rs` (+2 -16) 📝 `crates/horizon-client/src/game/fangs.rs` (+1 -5) 📝 `crates/horizon-client/src/game/leads.rs` (+3 -6) 📝 `crates/horizon-client/src/game/mob_blocks.rs` (+2 -9) 📝 `crates/horizon-client/src/game/wind.rs` (+3 -6) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What and why Six entity models were baked the first time one of their entities came into view, on the render thread, inside `entity_geometry`: the leash knot, the wind charge, the shulker bullet, the wither skull, the evoker fangs and the standing banner. Each one did it through a `OnceLock` that parsed the whole `entity-models.json` document again just for its one model. The first leash knot a player sees (and the first banner, wind charge…) cost one long frame. `HORIZON_SPIKES` caught it in a frame-pacing run (`tools/pacing_bench.py`, RD 12): **41.4 ms of render-thread CPU in one frame**, all of it in the leash knot's first draw (`eo_leash`, a lap of `entity_geometry`). The fix moves these six models to `GameCpuResources`, the startup worker that already parses the document once for the crystal, dragon, arrow, trident and armor stand models (`EntityModels::load`). The draw code reads the baked `Part` from `Game`. The models, their keys and their drawing don't change, so frames look the same. ## Measured playhorizon (8 vCPU, lavapipe software Vulkan at 320x180, load average 37–52), `pacing_bench.py --distances 12 --spike-ms 8`, one run each. Lavapipe makes wall time GPU noise, so this compares the render thread's own CPU time per span, which `HORIZON_SPIKES` logs for every slow frame: | | main | this PR | |---|---|---| | Worst `entity_geometry` frame (render-thread CPU) | 41.6 ms | 4.6 ms | | of which an entity's first model bake (`eo_leash`) | 41.4 ms | none | | Worst frame of the whole run (render-thread CPU) | 48.7 ms | 20.8 ms | The 4.6 ms left is mob geometry (`eg_mobs`), which isn't touched here. The whole-frame figures (p50, p99, p99.9, max, lows, frames > 33 ms) on a software renderer are set by lavapipe, not by this. An A/B on a real GPU comes with the frame-pacing series. The cost removed is fixed CPU work, so it is the same order on any machine: one hitch per model type, per game. ## Checks **pr_ready** (`tools/pr_ready.py --quick` on playhorizon, against origin/main at 4bc8e359c, 9 min 4 s) | Check | Result | | --- | --- | | Scope | ✅ 6 files, +57 −43 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 598 passed (1 min 0 s) | | rustfmt | ✅ (13 s) | | clippy | ✅ (3 min 49 s) | | tests: horizon-client | ✅ 593 passed (3 min 51 s) | | doc tests | ✅ 0 passed (3 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 | ➖ 60 affected, to run in CI (--quick): armor_stand_frost, arrow, arrow_wind_charge, blending, block_particles, block_removal, block_tint, boat_authority, boat_paddle_reset, boat_submerged, breaking_model, command_exec and 48 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | Gameplay and rendering: same models, same keys, same draw calls; `startup_cpu_tests::worker_prepares_owned_models_and_inventory_before_handoff` now asserts the six models are prepared on the worker. 🤖 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 06:32:07 +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#7015
No description provided.