[PR #841] [MERGED] Server: track each entity once for all its clients, as vanilla's ServerEntity #2852

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

📋 Pull Request Information

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

Base: main ← Head: perf/tracker-dirty-data


📝 Commits (1)

  • c63fa74 Server: track each entity once for all its clients, as vanilla's ServerEntity

📊 Changes

3 files changed (+528 additions, -242 deletions)

View changed files

📝 crates/horizon-client/src/lan/conn.rs (+13 -0)
📝 crates/horizon-client/src/lan/entity.rs (+462 -176)
📝 crates/horizon-client/src/lan/hub.rs (+53 -66)

📄 Description

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

What

Entity tracking on the server, in vanilla's shape (ChunkMap.TrackedEntity / ServerEntity):

  • A level keeps one ServerEntity state per entity (lan::entity::Entities, by dimension in the hub), not one per guest. Its changes (sendChanges: moves, rotation, motion, dirty entity data, head, equipment, passengers) are worked out once a tick, encoded once and sent to every guest tracking it.
  • Entity data is compared once per entity per tick (SynchedEntityData.isDirty), not once per guest per entity.
  • The update cadence is the entity's own tickCount against its type's updateInterval, as vanilla's, so every client gets an entity's updates on the same ticks. A client that starts tracking an entity later is paired (sendPairingData) with the data and equipment the others hold, then gets the same updates.
  • A guest's Tracker is now just the set of entities it is paired with (seenBy).
  • Gone from the per-tick path: the clone of every EntityState, the id list per guest, the HashMap from ids to entities, packet lists allocated per guest per entity, and one encode per guest per packet. Each guest's packets for the tick go to its connection under one lock (PlayerSender::send_many).

The packets each client receives are those vanilla's server sends: per entity, in order, with the same pairing, changes and removals as before. Only the tick on which a late-pairing client gets an entity's next move changes, from its own counter to the entity's (vanilla's).

Why

perf-server-6/8 profiles: tick_lan is 40–60 % of the server's world tick, and the per-player entity update was the biggest part of it with many players and entities: every guest compared every entity's data and built and encoded its packets on its own.

Measured

Mac mini M4 Pro (busy and shared: alternating runs; sample of the engine's main thread, 20 s per run). Flat world, 40 horizon-bots walking around spawn, about 600 entities summoned around spawn (animals, villagers, wolves, husks, items, armor stands, minecarts, boats, arrows), /tick query every 5 s for 60 s after a 20 s warm-up.

run MSPT avg P50 P95 world tick samples tick_lan tick_level entity tracking
main #1 35.5 27.2 93.4 6034 3140 2066 Tracker::update 853 + rest inlined
this #1 28.8 19.7 81.5 5961 1941 627 track_entities 443
main #2 39.9 29.7 110.9 6505 3406 2116 Tracker::update 919 + rest inlined
this #2 31.9 20.1 99.0 5558 1537 434 track_entities 265

On main, Tracker::update alone was 850–920 samples (comparing entity data, Value::eq, about a quarter of it), plus the per-guest id lists, encoding and sends inlined into tick_level. With this change all of entity tracking is 265–443 samples, most of it the per-pair range check. tick_lan is 40–55 % cheaper and MSPT about 20 % lower in both pairs.

How tested

Run on the Mac mini, on an integration commit of this PR and the locator bar one (#842), rebased on main:

cargo fmt --all --check                                          ok
cargo clippy --workspace --all-targets -- -D warnings            ok
cargo test -p horizon-client --lib                               864 passed, 0 failed
cargo test -p horizon-client --test lan_bot                      2 passed (guests see each other and the world's entities)
PARITY_LOCAL_JOBS=4 python3 tools/parity.py --changed origin/main
  before the last rebase: 93 passed, 1 failed (tooltip_display: its harness wrote Python's
  `False`; fixed on main by #837, and it passes on main and here since)
  on the rebased commit:  95 passed, 0 failed (32 min)

It includes server_entities (every entity kind's transcript against vanilla's dedicated server, exactly), dedicated_server, server_dimension_players, lan, locator_bar and the entity-data harnesses (entity_components, entity_model, entity_death_loot, entity_particles).

New unit tests in lan::entity: the old per-tracker tests on ServerEntity, plus two on Entities::tick: every client gets the same encoded changes and a late client is paired with what the others hold; clients lose what leaves their range or the level, and never track themselves.

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/841 **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/tracker-dirty-data` --- ### 📝 Commits (1) - [`c63fa74`](https://github.com/horizon-rust/horizon/commit/c63fa742393405cc57f8551a2eb1013af9bdbcdd) Server: track each entity once for all its clients, as vanilla's ServerEntity ### 📊 Changes **3 files changed** (+528 additions, -242 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/lan/conn.rs` (+13 -0) 📝 `crates/horizon-client/src/lan/entity.rs` (+462 -176) 📝 `crates/horizon-client/src/lan/hub.rs` (+53 -66) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What Entity tracking on the server, in vanilla's shape (`ChunkMap.TrackedEntity` / `ServerEntity`): - A level keeps **one `ServerEntity` state per entity** (`lan::entity::Entities`, by dimension in the hub), not one per guest. Its changes (`sendChanges`: moves, rotation, motion, dirty entity data, head, equipment, passengers) are worked out **once a tick**, encoded once and sent to every guest tracking it. - Entity data is compared **once per entity per tick** (`SynchedEntityData.isDirty`), not once per guest per entity. - The update cadence is the entity's own `tickCount` against its type's `updateInterval`, as vanilla's, so every client gets an entity's updates on the same ticks. A client that starts tracking an entity later is paired (`sendPairingData`) with the data and equipment the others hold, then gets the same updates. - A guest's `Tracker` is now just the set of entities it is paired with (`seenBy`). - Gone from the per-tick path: the clone of every `EntityState`, the id list per guest, the `HashMap` from ids to entities, packet lists allocated per guest per entity, and one encode per guest per packet. Each guest's packets for the tick go to its connection under one lock (`PlayerSender::send_many`). The packets each client receives are those vanilla's server sends: per entity, in order, with the same pairing, changes and removals as before. Only the tick on which a late-pairing client gets an entity's next move changes, from its own counter to the entity's (vanilla's). ## Why perf-server-6/8 profiles: `tick_lan` is 40–60 % of the server's world tick, and the per-player entity update was the biggest part of it with many players and entities: every guest compared every entity's data and built and encoded its packets on its own. ## Measured Mac mini M4 Pro (busy and shared: alternating runs; `sample` of the engine's main thread, 20 s per run). Flat world, 40 `horizon-bots` walking around spawn, about 600 entities summoned around spawn (animals, villagers, wolves, husks, items, armor stands, minecarts, boats, arrows), `/tick query` every 5 s for 60 s after a 20 s warm-up. | run | MSPT avg | P50 | P95 | world tick samples | `tick_lan` | `tick_level` | entity tracking | | --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | | main #1 | 35.5 | 27.2 | 93.4 | 6034 | 3140 | 2066 | `Tracker::update` 853 + rest inlined | | this #1 | 28.8 | 19.7 | 81.5 | 5961 | 1941 | 627 | `track_entities` 443 | | main #2 | 39.9 | 29.7 | 110.9 | 6505 | 3406 | 2116 | `Tracker::update` 919 + rest inlined | | this #2 | 31.9 | 20.1 | 99.0 | 5558 | 1537 | 434 | `track_entities` 265 | On main, `Tracker::update` alone was 850–920 samples (comparing entity data, `Value::eq`, about a quarter of it), plus the per-guest id lists, encoding and sends inlined into `tick_level`. With this change all of entity tracking is 265–443 samples, most of it the per-pair range check. `tick_lan` is 40–55 % cheaper and MSPT about 20 % lower in both pairs. ## How tested Run on the Mac mini, on an integration commit of this PR and the locator bar one (#842), rebased on main: ``` cargo fmt --all --check ok cargo clippy --workspace --all-targets -- -D warnings ok cargo test -p horizon-client --lib 864 passed, 0 failed cargo test -p horizon-client --test lan_bot 2 passed (guests see each other and the world's entities) PARITY_LOCAL_JOBS=4 python3 tools/parity.py --changed origin/main before the last rebase: 93 passed, 1 failed (tooltip_display: its harness wrote Python's `False`; fixed on main by #837, and it passes on main and here since) on the rebased commit: 95 passed, 0 failed (32 min) ``` It includes `server_entities` (every entity kind's transcript against vanilla's dedicated server, exactly), `dedicated_server`, `server_dimension_players`, `lan`, `locator_bar` and the entity-data harnesses (`entity_components`, `entity_model`, `entity_death_loot`, `entity_particles`). New unit tests in `lan::entity`: the old per-tracker tests on `ServerEntity`, plus two on `Entities::tick`: every client gets the same encoded changes and a late client is paired with what the others hold; clients lose what leaves their range or the level, and never track themselves. ## 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:35 +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#2852
No description provided.