[PR #798] [MERGED] Block entities: tick only those with a ticker, in vanilla's order #2820

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

📋 Pull Request Information

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

Base: main ← Head: perf/block-entity-tickers


📝 Commits (3)

  • ff94490 Block entities: tick only those with a ticker, in vanilla's order
  • 7de8c51 Block entity tickers: sweep the list only after a slot is freed
  • 5253e94 Dedicated server: skip the client ticks of spawners, trial spawners and vaults

📊 Changes

22 files changed (+1236 additions, -340 deletions)

View changed files

➕ crates/horizon-client/examples/block_entity_tickers_fixture.rs (+99 -0)
➕ crates/horizon-client/src/block_entities.rs (+395 -0)
📝 crates/horizon-client/src/game.rs (+3 -34)
📝 crates/horizon-client/src/game/beacon.rs (+7 -18)
📝 crates/horizon-client/src/game/beehives.rs (+34 -45)
➕ crates/horizon-client/src/game/block_entity_ticks.rs (+144 -0)
📝 crates/horizon-client/src/game/command_blocks.rs (+2 -2)
📝 crates/horizon-client/src/game/creaking.rs (+32 -41)
📝 crates/horizon-client/src/game/dispense_fixture.rs (+11 -1)
📝 crates/horizon-client/src/game/jukebox.rs (+42 -52)
📝 crates/horizon-client/src/game/machines.rs (+27 -34)
📝 crates/horizon-client/src/game/machines/crafter.rs (+24 -35)
📝 crates/horizon-client/src/game/render_control.rs (+1 -1)
📝 crates/horizon-client/src/game/spawner.rs (+21 -27)
📝 crates/horizon-client/src/game/trial_spawner.rs (+14 -27)
📝 crates/horizon-client/src/game/trial_visuals.rs (+1 -1)
📝 crates/horizon-client/src/game/vault.rs (+13 -19)
📝 crates/horizon-client/src/lib.rs (+1 -0)
📝 crates/horizon-client/src/streaming.rs (+1 -1)
📝 crates/horizon-client/src/world.rs (+15 -2)

...and 2 more files

📄 Description

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

What

tick_block_entities now ticks only what vanilla 26.3 ticks, in vanilla's order.

  • New horizon_client::block_entities::BlockEntities. It wraps World.block_entities and keeps Level.blockEntityTickers: a slot list in which each ticking position gets a slot.
    • Slots are added as pendingBlockEntityTickers are promoted at the start of the tick.
    • A replaced block entity keeps its slot. A state change that keeps a ticker rebinds it.
    • A slot is freed by removal, by unloading the chunk, or by a state without a ticker (a jukebox losing its record).
    • A loaded chunk registers its block entities in the iteration order of its fastutil Object2ObjectOpenHashMap.
    • Reads still go through Deref<Target = HashMap>. Borrowing an entity during a tick uses take/put, which keep the slot.
  • game/block_entity_ticks.rs. One pass over the slots:
    • Skips a slot freed earlier in the tick, a slot outside block-ticking range (DistanceManager.inBlockTickingRange, simulation distance + 1), and a slot outside the world border.
    • Dispatches each entity to its own tick: hopper, crafter, jukebox, beacon, creaking heart, spawner, trial spawner, vault, beehive or bee nest, and the three furnaces.
    • Each of those used to be a separate pass over the whole map that collected and filtered positions.
  • The slot list is swept only when a slot was freed or a block entity was taken out and not put back.
  • Dedicated and integrated servers skip client-only ticks for spawners, trial spawners and vaults: particles, ambient sounds, and the spinning display mob, which was being built for every spawner.

Behaviour changes, all matching vanilla

  • Order: list order, rather than one kind after another in hash-map order.
  • Block entities in chunks outside block-ticking range, or outside the world border, don't tick.
  • A dedicated server with no players ticks none.
  • A furnace's lit change applies when that furnace ticks, not after all of them.

Known deviations, unchanged by this PR:

  • Sculk, brewing stands and pistons still tick in their own passes.
  • A creaking heart keeps its slot while uprooted. Vanilla frees it. Keeping it preserves Horizon's existing lazy "block gone, remove the protector" cleanup. The harness corpus leaves hearts out.

Numbers

50 walk bots on main 9b97ba09, base and new run at the same time on the Mac mini (busy with other sessions). Shares are of the server thread's tick_world samples.

base r1 new r1 base r2 new r2
tick_block_entities share of tick_world 19.5% 9.6% 19.7% 11.9%
MSPT 29.1 24.7 37.9 29.3
CPU 29.5% 29.0% 35.2% 34.6%
chunks/s 496.8 495.4 494.6 496.2

An earlier round without the sweep and client-tick commits gave MSPT 24.6 / 20.5 → 21.0 / 18.2. With 30 explore bots, tick_block_entities fell from 946 to 685 samples, but MSPT is dominated by tick_lan and stayed within noise (86.9 / 107.3 → 86.8 / 109.9).

Most of what remains is the vault tick (vault_players), mob_world_base game-rule lookups, and block-state reads.

How tested

  • New harness tools/test_block_entity_tickers_parity.py. A vanilla oracle (VanillaBlockEntityTickerOracle) drives real LevelChunks of a ServerLevel through addAndRegisterBlockEntity, setBlockEntity, removeBlockEntity, updateBlockEntityTicker, registerAllBlockEntitiesAfterLevelLoad, clearAllBlockEntities and tickBlockEntities. It prints the ticker list after each tick.
    • Result: 3000 scenarios, 21590 of 21590 ticks match vanilla (742476 tickers listed).
  • Unit tests for the slot lifecycle, including take without put, and for the open-hash-map order.
  • cargo fmt --all --check: passes.
  • cargo clippy --workspace --all-targets -- -D warnings: passes.
  • cargo test -p horizon-client --lib: 840 passed, 0 failed, 11 ignored.
  • tools/parity.py --changed origin/main: 90 of 90 harnesses pass, including block_entity_tickers, crafter, dispenser, spawner, trial_spawner, vault and dedicated_server.

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/798 **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/block-entity-tickers` --- ### 📝 Commits (3) - [`ff94490`](https://github.com/horizon-rust/horizon/commit/ff9449099220d4039f93312652ba55d0d79a27c2) Block entities: tick only those with a ticker, in vanilla's order - [`7de8c51`](https://github.com/horizon-rust/horizon/commit/7de8c51f4eeb02d8194348edecdd99c4e7ee04e6) Block entity tickers: sweep the list only after a slot is freed - [`5253e94`](https://github.com/horizon-rust/horizon/commit/5253e94262755c809473cb956617fe52b45679ba) Dedicated server: skip the client ticks of spawners, trial spawners and vaults ### 📊 Changes **22 files changed** (+1236 additions, -340 deletions) <details> <summary>View changed files</summary> ➕ `crates/horizon-client/examples/block_entity_tickers_fixture.rs` (+99 -0) ➕ `crates/horizon-client/src/block_entities.rs` (+395 -0) 📝 `crates/horizon-client/src/game.rs` (+3 -34) 📝 `crates/horizon-client/src/game/beacon.rs` (+7 -18) 📝 `crates/horizon-client/src/game/beehives.rs` (+34 -45) ➕ `crates/horizon-client/src/game/block_entity_ticks.rs` (+144 -0) 📝 `crates/horizon-client/src/game/command_blocks.rs` (+2 -2) 📝 `crates/horizon-client/src/game/creaking.rs` (+32 -41) 📝 `crates/horizon-client/src/game/dispense_fixture.rs` (+11 -1) 📝 `crates/horizon-client/src/game/jukebox.rs` (+42 -52) 📝 `crates/horizon-client/src/game/machines.rs` (+27 -34) 📝 `crates/horizon-client/src/game/machines/crafter.rs` (+24 -35) 📝 `crates/horizon-client/src/game/render_control.rs` (+1 -1) 📝 `crates/horizon-client/src/game/spawner.rs` (+21 -27) 📝 `crates/horizon-client/src/game/trial_spawner.rs` (+14 -27) 📝 `crates/horizon-client/src/game/trial_visuals.rs` (+1 -1) 📝 `crates/horizon-client/src/game/vault.rs` (+13 -19) 📝 `crates/horizon-client/src/lib.rs` (+1 -0) 📝 `crates/horizon-client/src/streaming.rs` (+1 -1) 📝 `crates/horizon-client/src/world.rs` (+15 -2) _...and 2 more files_ </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What `tick_block_entities` now ticks only what vanilla 26.3 ticks, in vanilla's order. - **New `horizon_client::block_entities::BlockEntities`.** It wraps `World.block_entities` and keeps `Level.blockEntityTickers`: a slot list in which each ticking position gets a slot. - Slots are added as `pendingBlockEntityTickers` are promoted at the start of the tick. - A replaced block entity keeps its slot. A state change that keeps a ticker rebinds it. - A slot is freed by removal, by unloading the chunk, or by a state without a ticker (a jukebox losing its record). - A loaded chunk registers its block entities in the iteration order of its fastutil `Object2ObjectOpenHashMap`. - Reads still go through `Deref<Target = HashMap>`. Borrowing an entity during a tick uses `take`/`put`, which keep the slot. - **`game/block_entity_ticks.rs`.** One pass over the slots: - Skips a slot freed earlier in the tick, a slot outside block-ticking range (`DistanceManager.inBlockTickingRange`, simulation distance + 1), and a slot outside the world border. - Dispatches each entity to its own tick: hopper, crafter, jukebox, beacon, creaking heart, spawner, trial spawner, vault, beehive or bee nest, and the three furnaces. - Each of those used to be a separate pass over the whole map that collected and filtered positions. - The slot list is swept only when a slot was freed or a block entity was taken out and not put back. - **Dedicated and integrated servers skip client-only ticks** for spawners, trial spawners and vaults: particles, ambient sounds, and the spinning display mob, which was being built for every spawner. ## Behaviour changes, all matching vanilla - Order: list order, rather than one kind after another in hash-map order. - Block entities in chunks outside block-ticking range, or outside the world border, don't tick. - A dedicated server with no players ticks none. - A furnace's `lit` change applies when that furnace ticks, not after all of them. Known deviations, unchanged by this PR: - Sculk, brewing stands and pistons still tick in their own passes. - A creaking heart keeps its slot while uprooted. Vanilla frees it. Keeping it preserves Horizon's existing lazy "block gone, remove the protector" cleanup. The harness corpus leaves hearts out. ## Numbers 50 walk bots on main 9b97ba09, base and new run at the same time on the Mac mini (busy with other sessions). Shares are of the server thread's `tick_world` samples. | | base r1 | new r1 | base r2 | new r2 | |---|---:|---:|---:|---:| | `tick_block_entities` share of `tick_world` | 19.5% | 9.6% | 19.7% | 11.9% | | MSPT | 29.1 | 24.7 | 37.9 | 29.3 | | CPU | 29.5% | 29.0% | 35.2% | 34.6% | | chunks/s | 496.8 | 495.4 | 494.6 | 496.2 | An earlier round without the sweep and client-tick commits gave MSPT 24.6 / 20.5 → 21.0 / 18.2. With 30 explore bots, `tick_block_entities` fell from 946 to 685 samples, but MSPT is dominated by `tick_lan` and stayed within noise (86.9 / 107.3 → 86.8 / 109.9). Most of what remains is the vault tick (`vault_players`), `mob_world_base` game-rule lookups, and block-state reads. ## How tested - New harness `tools/test_block_entity_tickers_parity.py`. A vanilla oracle (`VanillaBlockEntityTickerOracle`) drives real `LevelChunk`s of a `ServerLevel` through `addAndRegisterBlockEntity`, `setBlockEntity`, `removeBlockEntity`, `updateBlockEntityTicker`, `registerAllBlockEntitiesAfterLevelLoad`, `clearAllBlockEntities` and `tickBlockEntities`. It prints the ticker list after each tick. - Result: **3000 scenarios, 21590 of 21590 ticks match vanilla (742476 tickers listed).** - Unit tests for the slot lifecycle, including take without put, and for the open-hash-map order. - `cargo fmt --all --check`: passes. - `cargo clippy --workspace --all-targets -- -D warnings`: passes. - `cargo test -p horizon-client --lib`: 840 passed, 0 failed, 11 ignored. - `tools/parity.py --changed origin/main`: 90 of 90 harnesses pass, including block_entity_tickers, crafter, dispenser, spawner, trial_spawner, vault and dedicated_server. ## 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:18 +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#2820
No description provided.