[PR #829] [MERGED] Block entity animations: read the drawn block entities only when they change #2840

Closed
opened 2026-11-02 15:59:28 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: perf/anim-tick-hash


📝 Commits (1)

  • 8f3d35a Block entity animations: read the drawn block entities only when they change

📊 Changes

3 files changed (+73 additions, -35 deletions)

View changed files

📝 crates/horizon-client/src/block_entity_anim.rs (+33 -22)
📝 crates/horizon-client/src/game/block_entity_anims.rs (+16 -9)
📝 crates/horizon-client/src/gfx.rs (+24 -4)

📄 Description

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

What

tick_block_entity_anims (the client-side tick of chest lids, enchanting-table books, bells, conduits and the like) no longer rebuilds its list of drawn block entities every tick.

Before: every client tick it

  • collected every block entity the renderer draws into a SipHash HashMap;
  • swept the animation states against that map (retain_present);
  • turned the map back into a Vec and sorted it by position;
  • then ticked each one.

With many block entities in view this was the main thread's biggest cost in the tick, even when nothing changed.

Now:

  • The renderer keeps block_entity_revision. It changes whenever its block entities change: a section uploaded with a different list, a section removed, all sections cleared. It is unique across renderers, so a new renderer never reuses an old value.
  • The sorted ticker list is kept in BlockEntityAnims and rebuilt only when that revision changes, or when the classification of states is reset.
  • retain_present takes the sorted list and uses a binary search. The animation state maps use FxHashMap.

What ticks, and in which order (sorted by position, as before), is unchanged.

Measured (Mac mini M4 Pro, shared with other sessions)

A single player in the frame, offscreen, creative flat world, RD 6, 32,768 chests and one brewing stand around the player. macOS sample of the whole process for 20 s, base and new interleaved.

main this PR
tick_block_entity_anims samples 4235 / 4578 / 8210 / 4352 / 7844 (mean 5844) 1065 / 1058 (−82 %)
tick_world samples 4874 / 5248 / 8959 / 4754 / 8557 3054 / 2829
process CPU over the 20 s 6.95 / 6.97 / 3.97 / 5.74 / 4.17 s 2.50 / 2.96 s

What remains in tick_block_entity_anims is the per-chest lid tick itself (one map lookup per chest), as vanilla's ChestBlockEntity.lidAnimateTick does per chest.

Checks

  • cargo fmt --all --check and cargo clippy --workspace --all-targets -- -D warnings: clean. cargo test -p horizon-client --lib: 861 passed (on the integration below).
  • tools/lan_e2e.py chest containers trials: pass (chest lids, containers and trial spawners/vaults seen by a guest).
  • Parity, on an integration of this PR with #824, #827 and #828 on main 5b62d771: the 19 harnesses that cover these changes pass (light, lan, dedicated_server, save_roundtrip, world_reopen, disk, datafix ×6, world, server_world_gen, block_entity_tickers, block_entity_anim, block_entity_render, block_entity_storage, chunk_stage). --changed selects about 300 harnesses because nearly all of them link horizon-client; the first 29 of those passed too before I stopped the run on the busy Mac mini, and CI parity covers the rest.

Needs Ludovic

Nothing.

🤖 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/829 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/18/2026 **Status:** ✅ Merged **Merged:** 10/18/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/anim-tick-hash` --- ### 📝 Commits (1) - [`8f3d35a`](https://github.com/horizon-rust/horizon/commit/8f3d35ab6df5a000bd0be437d8b060eae8ff4960) Block entity animations: read the drawn block entities only when they change ### 📊 Changes **3 files changed** (+73 additions, -35 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/block_entity_anim.rs` (+33 -22) 📝 `crates/horizon-client/src/game/block_entity_anims.rs` (+16 -9) 📝 `crates/horizon-client/src/gfx.rs` (+24 -4) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What `tick_block_entity_anims` (the client-side tick of chest lids, enchanting-table books, bells, conduits and the like) no longer rebuilds its list of drawn block entities every tick. **Before:** every client tick it - collected every block entity the renderer draws into a SipHash `HashMap`; - swept the animation states against that map (`retain_present`); - turned the map back into a `Vec` and sorted it by position; - then ticked each one. With many block entities in view this was the main thread's biggest cost in the tick, even when nothing changed. **Now:** - The renderer keeps `block_entity_revision`. It changes whenever its block entities change: a section uploaded with a different list, a section removed, all sections cleared. It is unique across renderers, so a new renderer never reuses an old value. - The sorted ticker list is kept in `BlockEntityAnims` and rebuilt only when that revision changes, or when the classification of states is reset. - `retain_present` takes the sorted list and uses a binary search. The animation state maps use `FxHashMap`. What ticks, and in which order (sorted by position, as before), is unchanged. ## Measured (Mac mini M4 Pro, shared with other sessions) A single player in the frame, offscreen, creative flat world, RD 6, 32,768 chests and one brewing stand around the player. macOS `sample` of the whole process for 20 s, base and new interleaved. | | main | this PR | |---|---|---| | `tick_block_entity_anims` samples | 4235 / 4578 / 8210 / 4352 / 7844 (mean 5844) | **1065 / 1058** (−82 %) | | `tick_world` samples | 4874 / 5248 / 8959 / 4754 / 8557 | 3054 / 2829 | | process CPU over the 20 s | 6.95 / 6.97 / 3.97 / 5.74 / 4.17 s | 2.50 / 2.96 s | What remains in `tick_block_entity_anims` is the per-chest lid tick itself (one map lookup per chest), as vanilla's `ChestBlockEntity.lidAnimateTick` does per chest. ## Checks - `cargo fmt --all --check` and `cargo clippy --workspace --all-targets -- -D warnings`: clean. `cargo test -p horizon-client --lib`: 861 passed (on the integration below). - `tools/lan_e2e.py chest containers trials`: pass (chest lids, containers and trial spawners/vaults seen by a guest). - Parity, on an integration of this PR with #824, #827 and #828 on main 5b62d771: the 19 harnesses that cover these changes pass (`light`, `lan`, `dedicated_server`, `save_roundtrip`, `world_reopen`, `disk`, `datafix` ×6, `world`, `server_world_gen`, `block_entity_tickers`, `block_entity_anim`, `block_entity_render`, `block_entity_storage`, `chunk_stage`). `--changed` selects about 300 harnesses because nearly all of them link horizon-client; the first 29 of those passed too before I stopped the run on the busy Mac mini, and CI parity covers the rest. ## Needs Ludovic Nothing. 🤖 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-02 15:59:28 +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#2840
No description provided.