[PR #2012] [MERGED] Mob models: one Poses per mob per frame, not one per equipment layer #3938

Closed
opened 2026-11-03 04:13:24 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: perf/poses-layer-reuse


📝 Commits (3)

  • d41aa95 Mob models: one Poses per mob per frame, not one per equipment layer
  • 2918f31 Poses::reset clears the scratch pose too
  • 7e047c4 Merge remote-tracking branch 'origin/main' into perf/poses-layer-reuse

📊 Changes

2 files changed (+29 additions, -13 deletions)

View changed files

📝 crates/horizon-client/src/mobs/anim.rs (+13 -9)
📝 crates/horizon-client/src/mobs/render.rs (+16 -4)

📄 Description

🤖 Opened by Alexander's AI agent (Hermes), not by Alexander himself.

mobs/render.rs and mobs/anim.rs: render_with built a fresh Poses for every equipment layer of a mob, and each one walked the model again and allocated its own HashMap plus two HashSets. A humanoid wearing armour draws five to seven layers, so that was five to seven dictionary allocations per mob per frame, thrown away immediately.

Poses now has reset(&mut self, model), which clears the three collections and refills them, so the capacity survives; the layers share one instance created before the loop. Poses::new stays for the body draw and its other callers, defined in terms of reset.

No behaviour change: the same parts are inserted with the same poses, reset clears skipped and hidden exactly as a fresh instance would have them empty, and the body keeps its own instance because it is still borrowed after the layer loop.

No number, and I would rather say so than invent one. tools/graphics_bench.py cannot run on this machine at all — it drives vscreen, a Linux virtual screen, and dies with FileNotFoundError: vscreen — and the client's own --benchmark village reports cpu_p50 0.326 ms with very few mobs, so a per-layer dictionary allocation does not rise above its resolution. On a mob-heavy scene the saving is a few thousand HashMap allocations per frame; this PR does not claim a measured frame-time win, only that the allocations stop.

cargo fmt --all --check and cargo clippy -p horizon-client --all-targets -- -D warnings pass.


🔄 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/2012 **Author:** [@Domanffe](https://github.com/Domanffe) **Created:** 10/26/2026 **Status:** ✅ Merged **Merged:** 10/26/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/poses-layer-reuse` --- ### 📝 Commits (3) - [`d41aa95`](https://github.com/horizon-rust/horizon/commit/d41aa95dbd6cde12ed4d6bb78141e91f8c21b28d) Mob models: one Poses per mob per frame, not one per equipment layer - [`2918f31`](https://github.com/horizon-rust/horizon/commit/2918f3181182d92165a73035c0564486992a9b41) Poses::reset clears the scratch pose too - [`7e047c4`](https://github.com/horizon-rust/horizon/commit/7e047c409cecbd2bcaf410bd12138e398a7f8250) Merge remote-tracking branch 'origin/main' into perf/poses-layer-reuse ### 📊 Changes **2 files changed** (+29 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/mobs/anim.rs` (+13 -9) 📝 `crates/horizon-client/src/mobs/render.rs` (+16 -4) </details> ### 📄 Description > 🤖 Opened by Alexander's AI agent (Hermes), not by Alexander himself. `mobs/render.rs` and `mobs/anim.rs`: `render_with` built a fresh `Poses` for every equipment layer of a mob, and each one walked the model again and allocated its own `HashMap` plus two `HashSet`s. A humanoid wearing armour draws five to seven layers, so that was five to seven dictionary allocations per mob per frame, thrown away immediately. `Poses` now has `reset(&mut self, model)`, which clears the three collections and refills them, so the capacity survives; the layers share one instance created before the loop. `Poses::new` stays for the body draw and its other callers, defined in terms of `reset`. No behaviour change: the same parts are inserted with the same poses, `reset` clears `skipped` and `hidden` exactly as a fresh instance would have them empty, and the body keeps its own instance because it is still borrowed after the layer loop. No number, and I would rather say so than invent one. `tools/graphics_bench.py` cannot run on this machine at all — it drives `vscreen`, a Linux virtual screen, and dies with `FileNotFoundError: vscreen` — and the client's own `--benchmark village` reports `cpu_p50 0.326 ms` with very few mobs, so a per-layer dictionary allocation does not rise above its resolution. On a mob-heavy scene the saving is a few thousand `HashMap` allocations per frame; this PR does not claim a measured frame-time win, only that the allocations stop. `cargo fmt --all --check` and `cargo clippy -p horizon-client --all-targets -- -D warnings` pass. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 04:13:24 +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#3938
No description provided.