[PR #927] [MERGED] Entity tracking: check a pair again only when one side moves, as vanilla's ChunkMap #2920

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

📋 Pull Request Information

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

Base: main ← Head: fix/lazy-pair-recheck


📝 Commits (1)

  • 3cd1557 Entity tracking: check a pair again only when one side moves, as vanilla's ChunkMap

📊 Changes

4 files changed (+163 additions, -15 deletions)

View changed files

📝 crates/horizon-client/src/lan/entity.rs (+133 -14)
📝 crates/horizon-client/src/lan/guest.rs (+4 -0)
📝 crates/horizon-client/src/lan/hub.rs (+3 -0)
📝 crates/horizon-client/tests/lan_bot.rs (+23 -1)

📄 Description

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

What

Entity tracking now checks a client's pairs again only when vanilla's ChunkMap does, instead of every pair on every tick:

  • A client that accepted a move since the last tick (ServerChunkCache.move, called from handlePlayerPositionChange once a move is accepted) has all of its pairs checked again. Its Guest::moved flag is set where the move is accepted and taken by the next range checks.
  • A client whose own entity appeared or changed section (ChunkMap.tick's movedPlayers, addEntity) has all of its pairs checked again too. That covers teleports and respawns, which vanilla also re-checks only through the section change (teleportTo doesn't call move).
  • An entity that appeared or changed section (TrackedEntity.lastSectionPos, the updatePlayers in ChunkMap.tick and addEntity) is checked against every client.
  • Any other pair stays as it was. A client with nothing to re-check takes its pairs from what it tracks, plus checks only for the entities that moved section. It goes through the level's list in order when it tracks much of it, and through its tracked set otherwise.

Not ported, because Horizon's guests don't have them: handleMoveVehicle's move (no server-side vehicle moves for guests) and the spectator camera's (ServerPlayer.tick, setCamera).

Behaviour change (vanilla's timing)

For a client that sends no move that tick (vanilla's client sends its position at least every 20 ticks when standing still), an entity walking into range within its section, or standing in a chunk that has just arrived, is paired at the next re-check (the client's next move, or the entity changing section) rather than on the same tick. One walking out of range stays tracked until one side re-checks. Clients that move, and every bot in the benchmarks, move every tick, so nothing changes for them. Brief perf-server-10 records this as decided: port it.

Numbers

Entities::tick alone, 40 standing clients and 640 zombies wandering 0.05 blocks a tick, 1000 ticks, median per tick, M4 Pro (busy). Both columns ran in one binary, interleaved 3x: "every pair" marks every client as moved, which is today's code path.

every pair (today) this PR
dense: all within 48 blocks, each client tracks ~all 680 68.6 µs 49.4 µs (-28 %)
spread 10x (960 x 960 blocks), each tracks a few 39.0 µs 15.2 µs (-61 %)

Packets sent differ by under 0.4 %: the later pairings above.

Checks

  • cargo fmt --all --check, cargo clippy --workspace --all-targets -- -D warnings: clean.
  • cargo test -p horizon-client: passes on 3cd15579 (881 lib, 75 bin and every integration test, lan_bot included). New test pairs_are_checked_again_when_a_side_moves: a zombie walking into range in its section isn't paired with a standing client until the client moves; one walking out stays tracked until it changes section. The other tracking tests run unchanged (their clients' entities aren't in the level, so every pair is checked as before).
  • tests/lan_bot.rs: in guests_see_each_other_and_the_world_entities, the first bot stood still and only accepted teleports, so with vanilla's timing the stationary zombie, whose chunk arrived after the bot's last accepted move, was never paired. The bot now sends its position once a second, as vanilla's client does (LocalPlayer's positionReminder, at least every 20 ticks).
  • Parity lan, dedicated_server, server_entities, server_dimension_players, server_player_targets: 5 passed, 0 failed, twice, on 09b4e35d (the same code; 3cd15579 only changes tests/lan_bot.rs). CI parity covers the rest of --changed.

Needs Ludovic

Nothing to merge it. The behaviour change above is the one the brief decided to port.

🤖 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/927 **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:** `fix/lazy-pair-recheck` --- ### 📝 Commits (1) - [`3cd1557`](https://github.com/horizon-rust/horizon/commit/3cd155792d442c6c7d16b0d8760081b37c7b3dc5) Entity tracking: check a pair again only when one side moves, as vanilla's ChunkMap ### 📊 Changes **4 files changed** (+163 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/lan/entity.rs` (+133 -14) 📝 `crates/horizon-client/src/lan/guest.rs` (+4 -0) 📝 `crates/horizon-client/src/lan/hub.rs` (+3 -0) 📝 `crates/horizon-client/tests/lan_bot.rs` (+23 -1) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What Entity tracking now checks a client's pairs again only when vanilla's `ChunkMap` does, instead of every pair on every tick: - **A client that accepted a move** since the last tick (`ServerChunkCache.move`, called from `handlePlayerPositionChange` once a move is accepted) has all of its pairs checked again. Its `Guest::moved` flag is set where the move is accepted and taken by the next range checks. - **A client whose own entity appeared or changed section** (`ChunkMap.tick`'s `movedPlayers`, `addEntity`) has all of its pairs checked again too. That covers teleports and respawns, which vanilla also re-checks only through the section change (`teleportTo` doesn't call `move`). - **An entity that appeared or changed section** (`TrackedEntity.lastSectionPos`, the `updatePlayers` in `ChunkMap.tick` and `addEntity`) is checked against every client. - **Any other pair stays as it was.** A client with nothing to re-check takes its pairs from what it tracks, plus checks only for the entities that moved section. It goes through the level's list in order when it tracks much of it, and through its tracked set otherwise. Not ported, because Horizon's guests don't have them: `handleMoveVehicle`'s `move` (no server-side vehicle moves for guests) and the spectator camera's (`ServerPlayer.tick`, `setCamera`). ## Behaviour change (vanilla's timing) For a client that sends no move that tick (vanilla's client sends its position at least every 20 ticks when standing still), an entity walking into range within its section, or standing in a chunk that has just arrived, is paired at the next re-check (the client's next move, or the entity changing section) rather than on the same tick. One walking out of range stays tracked until one side re-checks. Clients that move, and every bot in the benchmarks, move every tick, so nothing changes for them. Brief perf-server-10 records this as decided: port it. ## Numbers `Entities::tick` alone, 40 standing clients and 640 zombies wandering 0.05 blocks a tick, 1000 ticks, median per tick, M4 Pro (busy). Both columns ran in one binary, interleaved 3x: "every pair" marks every client as moved, which is today's code path. | | every pair (today) | this PR | |---|---|---| | dense: all within 48 blocks, each client tracks ~all 680 | 68.6 µs | 49.4 µs (-28 %) | | spread 10x (960 x 960 blocks), each tracks a few | 39.0 µs | 15.2 µs (-61 %) | Packets sent differ by under 0.4 %: the later pairings above. ## Checks - `cargo fmt --all --check`, `cargo clippy --workspace --all-targets -- -D warnings`: clean. - `cargo test -p horizon-client`: passes on 3cd15579 (881 lib, 75 bin and every integration test, `lan_bot` included). New test `pairs_are_checked_again_when_a_side_moves`: a zombie walking into range in its section isn't paired with a standing client until the client moves; one walking out stays tracked until it changes section. The other tracking tests run unchanged (their clients' entities aren't in the level, so every pair is checked as before). - `tests/lan_bot.rs`: in `guests_see_each_other_and_the_world_entities`, the first bot stood still and only accepted teleports, so with vanilla's timing the stationary zombie, whose chunk arrived after the bot's last accepted move, was never paired. The bot now sends its position once a second, as vanilla's client does (`LocalPlayer`'s `positionReminder`, at least every 20 ticks). - Parity `lan`, `dedicated_server`, `server_entities`, `server_dimension_players`, `server_player_targets`: 5 passed, 0 failed, twice, on 09b4e35d (the same code; 3cd15579 only changes `tests/lan_bot.rs`). CI parity covers the rest of `--changed`. ## Needs Ludovic Nothing to merge it. The behaviour change above is the one the brief decided to port. 🤖 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 16:00: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#2920
No description provided.