[PR #7496] [MERGED] Pose each mob once per frame and name its layers without allocating #7629

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

📋 Pull Request Information

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

Base: main ← Head: perf/mob-layer-names


📝 Commits (2)

  • 9962001 Pose each mob's model once per frame, not once per layer
  • 8fd7585 Name mob layers without allocating each frame

📊 Changes

11 files changed (+365 additions, -149 deletions)

View changed files

📝 crates/horizon-client/src/game/armor_stands.rs (+1 -5)
📝 crates/horizon-client/src/game/creatures.rs (+1 -5)
📝 crates/horizon-client/src/game/item_draw.rs (+1 -5)
📝 crates/horizon-client/src/item_render.rs (+2 -10)
📝 crates/horizon-client/src/mobs.rs (+3 -3)
📝 crates/horizon-client/src/mobs/anim.rs (+103 -14)
📝 crates/horizon-client/src/mobs/camel.rs (+1 -1)
📝 crates/horizon-client/src/mobs/rabbit.rs (+1 -1)
📝 crates/horizon-client/src/mobs/render.rs (+160 -75)
📝 crates/horizon-client/src/mobs/skin.rs (+90 -28)
📝 crates/horizon-client/src/mobs/villager.rs (+2 -2)

📄 Description

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

Cuts the CPU cost of each mob drawn per frame (stress_mobs: 1000 mobs; villages) without changing a single vertex.

What changes

  • Poses once per frame, not once per layer. A layer that uses the body's own model (villager clothes, profession and level layers, spider eyes, sheep wool…) copies the body's poses instead of resetting and re-running the animation. Poses gets a version number that changes on every edit; Skin::draw reuses the walk it just did when the model, the base matrix and the pose version are the same, and only repaints the jobs. A villager's 4 draws are one walk.
  • Pose maps from a pool. Poses::pooled() reuses maps per thread instead of growing fresh FxHashMaps for each mob (reserve_rehash was 11 % of mob geometry).
  • No names built per frame. body() and layers() returned Strings from format! for every mob each frame (16 per spider for its legs). Layer names are now Cow<'static, str>; names built from parts are interned per thread (at most 4096, then owned again). Spider legs use static name pairs. MobType.layers uses FxHashMap instead of SipHash.
  • humanoid_armor returns at once for a mob with no armour and drops a format! per slot.

Proof (bit-exact)

  • CPU vertex digest of every mob type × 3 ages × 6 variants with armour (90 types, 508,104 vertices, 1,620 digest lines): byte-identical on main and on this branch (temporary test, not committed).
  • mobs::skin, mobs::anim, mobs::render, villager, creatures tests pass with prepared resources; the every-mob GPU/CPU byte test now uses a farmer villager so clothes, profession and level layers go through the repeat path.

Measured (Mac mini M4 Pro, perf_bench, stress_mobs, RD 16, 720p offscreen, 3 alternating A/B pairs, load falling 187 → 26 during the run)

main this PR
avg fps (3 runs) 440 / 423 / 417 (427) 479 / 506 / 557 (514, +20 %)
frame CPU p50 2.27 ms 1.87 ms (−18 %)
1 % low 276 / 290 / 181 187 / 287 / 348 (noisy)

Vanilla 26.3 on the same scene: 83 fps. The machine load fell during the run and each pair ran main first, so part of the gain may be load; the CPU micro-bench below has no such bias.

CPU micro-bench: render_skinned over 2000 mobs of the stress_mobs mix (husk, creeper, cow, pig, sheep, chicken, villager, spider), best of 40 frames, release build, playhorizon x86-64, 3 alternating pairs; each side built once:

µs per mob main this PR
GPU posing (today's renderer) 3.73 / 4.53 / 3.73 2.42 / 2.50 / 2.49 (−33 %)
CPU posing (renderer without tagged layers) 4.86 / 5.39 / 4.92 3.69 / 3.84 / 3.84 (−23 %)
model parts walked per frame (GPU path) 28,572 20,332 (−29 %)

No player-visible change: same vertices, same draw order.

pr_ready (tools/pr_ready.py --quick on playhorizon, against origin/main at b53cfcd14, 47 min 2 s)

Check Result
Scope ⚠️ 11 files, +365 −149; 514 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 614 passed (1 min 16 s)
rustfmt ✅ (15 s)
clippy ✅ (3 min 58 s)
tests: horizon-client, horizon-client-lib ✅ 2161 passed (40 min 1 s)
doc tests ✅ 0 passed (6 s)
content root tests ➖ content root untouched
mod API up to date ✅ (43 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 140 affected, to run in CI (--quick): ambient_sound, anvil_turtle_egg, armor_stand_frost, armor_stand_turtle_egg, arrow, arrow_wind_charge, audio_attributes, auto_jump, block_entity_anim, block_entity_render, block_entity_tickers, block_particles and 128 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🤖 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/7496 **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/mob-layer-names` --- ### 📝 Commits (2) - [`9962001`](https://github.com/horizon-rust/horizon/commit/9962001d0a9d7afa636a240d2fb691c37d08b4a1) Pose each mob's model once per frame, not once per layer - [`8fd7585`](https://github.com/horizon-rust/horizon/commit/8fd758551d76d6fc947c6fca27afc15b50f1802d) Name mob layers without allocating each frame ### 📊 Changes **11 files changed** (+365 additions, -149 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/armor_stands.rs` (+1 -5) 📝 `crates/horizon-client/src/game/creatures.rs` (+1 -5) 📝 `crates/horizon-client/src/game/item_draw.rs` (+1 -5) 📝 `crates/horizon-client/src/item_render.rs` (+2 -10) 📝 `crates/horizon-client/src/mobs.rs` (+3 -3) 📝 `crates/horizon-client/src/mobs/anim.rs` (+103 -14) 📝 `crates/horizon-client/src/mobs/camel.rs` (+1 -1) 📝 `crates/horizon-client/src/mobs/rabbit.rs` (+1 -1) 📝 `crates/horizon-client/src/mobs/render.rs` (+160 -75) 📝 `crates/horizon-client/src/mobs/skin.rs` (+90 -28) 📝 `crates/horizon-client/src/mobs/villager.rs` (+2 -2) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Cuts the CPU cost of each mob drawn per frame (stress_mobs: 1000 mobs; villages) without changing a single vertex. **What changes** - **Poses once per frame, not once per layer.** A layer that uses the body's own model (villager clothes, profession and level layers, spider eyes, sheep wool…) copies the body's poses instead of resetting and re-running the animation. `Poses` gets a version number that changes on every edit; `Skin::draw` reuses the walk it just did when the model, the base matrix and the pose version are the same, and only repaints the jobs. A villager's 4 draws are one walk. - **Pose maps from a pool.** `Poses::pooled()` reuses maps per thread instead of growing fresh `FxHashMap`s for each mob (`reserve_rehash` was 11 % of mob geometry). - **No names built per frame.** `body()` and `layers()` returned `String`s from `format!` for every mob each frame (16 per spider for its legs). Layer names are now `Cow<'static, str>`; names built from parts are interned per thread (at most 4096, then owned again). Spider legs use static name pairs. `MobType.layers` uses `FxHashMap` instead of SipHash. - `humanoid_armor` returns at once for a mob with no armour and drops a `format!` per slot. **Proof (bit-exact)** - CPU vertex digest of every mob type × 3 ages × 6 variants with armour (90 types, 508,104 vertices, 1,620 digest lines): byte-identical on main and on this branch (temporary test, not committed). - `mobs::skin`, `mobs::anim`, `mobs::render`, `villager`, `creatures` tests pass with prepared resources; the every-mob GPU/CPU byte test now uses a farmer villager so clothes, profession and level layers go through the repeat path. **Measured** (Mac mini M4 Pro, `perf_bench`, stress_mobs, RD 16, 720p offscreen, 3 alternating A/B pairs, load falling 187 → 26 during the run) | | main | this PR | |---|---|---| | avg fps (3 runs) | 440 / 423 / 417 (427) | 479 / 506 / 557 (514, **+20 %**) | | frame CPU p50 | 2.27 ms | 1.87 ms (−18 %) | | 1 % low | 276 / 290 / 181 | 187 / 287 / 348 (noisy) | Vanilla 26.3 on the same scene: 83 fps. The machine load fell during the run and each pair ran main first, so part of the gain may be load; the CPU micro-bench below has no such bias. CPU micro-bench: `render_skinned` over 2000 mobs of the stress_mobs mix (husk, creeper, cow, pig, sheep, chicken, villager, spider), best of 40 frames, release build, playhorizon x86-64, 3 alternating pairs; each side built once: | µs per mob | main | this PR | |---|---|---| | GPU posing (today's renderer) | 3.73 / 4.53 / 3.73 | 2.42 / 2.50 / 2.49 (**−33 %**) | | CPU posing (renderer without tagged layers) | 4.86 / 5.39 / 4.92 | 3.69 / 3.84 / 3.84 (−23 %) | | model parts walked per frame (GPU path) | 28,572 | 20,332 (−29 %) | No player-visible change: same vertices, same draw order. **pr_ready** (`tools/pr_ready.py --quick` on playhorizon, against origin/main at b53cfcd14, 47 min 2 s) | Check | Result | | --- | --- | | Scope | ⚠️ 11 files, +365 −149; 514 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 614 passed (1 min 16 s) | | rustfmt | ✅ (15 s) | | clippy | ✅ (3 min 58 s) | | tests: horizon-client, horizon-client-lib | ✅ 2161 passed (40 min 1 s) | | doc tests | ✅ 0 passed (6 s) | | content root tests | ➖ content root untouched | | mod API up to date | ✅ (43 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 140 affected, to run in CI (--quick): ambient_sound, anvil_turtle_egg, armor_stand_frost, armor_stand_turtle_egg, arrow, arrow_wind_charge, audio_attributes, auto_jump, block_entity_anim, block_entity_render, block_entity_tickers, block_particles and 128 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | 🤖 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:21:06 +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#7629
No description provided.