[PR #1195] [MERGED] LAN: write each tick's entity states over the last tick's (tick_lan −15 % at 40 players) #3409

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

📋 Pull Request Information

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

Base: main ← Head: perf/lan-entity-states


📝 Commits (1)

  • 83d0014 LAN: write each tick's entity states over the last tick's

📊 Changes

4 files changed (+149 additions, -93 deletions)

View changed files

📝 crates/horizon-client/src/game/lan.rs (+46 -74)
📝 crates/horizon-client/src/game/lan_attributes.rs (+8 -10)
📝 crates/horizon-client/src/game/lan_entities.rs (+3 -8)
📝 crates/horizon-client/src/lan/entity.rs (+92 -1)

📄 Description

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

What

tick_lan described every entity the guests track from scratch on every tick: for each mob, item and orb a new String for its type, new vectors for its entity data, equipment and attributes, all freed again at the end of the tick. On a 40-player server that was a few thousand allocations and frees per tick on the server thread.

The states now stay in the LAN host between ticks (lan::entity::States). Each tick writes over the previous tick's states in place (EntityState::reset, then the same fields as before), so those strings and vectors keep their allocations. mob_meta, mob_equipment and mob_attributes write into the state's vectors instead of returning new ones. The rarer entities (boats, carts, stands, frames, paintings, projectiles, the dragon) are still built as before and pushed into the same list.

Why

Brief perf-server-13, target 1. Profile of a 40-bot dedicated server (ThinkPad i7-7500U, perf record --call-graph lbr on the server thread): tick_lan was 18–19 % of the server thread, of which rebuilding the states (lan_entities plus dropping last tick's Vec<EntityState>) was about 4.4 points, mostly malloc/free.

Packets

Unchanged. The states hold the same values in the same order as before, and everything the tracker sends is built from them (Entities::tick compares them with what it last sent, exactly as before). The new States buffer is tested: a reused slot is equal to a freshly built state and keeps its allocations. The lan, tab_list, server_player_targets and online_mode harnesses, which compare what a client receives against vanilla, pass.

Numbers

ThinkPad server (i7-7500U, 2 cores / 4 threads, nice 19), 40 bots on the desktop over Tailscale, tools/server_bench.py --servers horizon --bots 40 --behaviour mixed --explore-speed 0.8 --warmup 120 --seconds 180 --nice 19, seed 12345, view distance 10, HORIZON_SPIKES=0 for the per-tick spans (averaged over the last 3,600 ticks). Release builds of main e730dc14 with and without this change, run interleaved (base, this, other, other, this, base, base, this, other):

run MSPT avg p95 p99 CPU ms/tick (server thread) tick_lan ms/tick mobs chunks/s
main 1 / 2 / 3 30.32 / 31.14 / 30.85 50.9 / 55.0 / 50.7 83.2 / 83.0 / 84.4 29.19 / 29.85 / 29.28 5.14 / 5.22 / 5.28 455 / 449 / 450 246.8 / 246.9 / 247.3
this 1 / 2 / 3 30.51 / 30.38 / 30.39 55.3 / 54.4 / 55.5 80.8 / 80.8 / 84.5 29.29 / 29.26 / 29.06 4.38 / 4.35 / 4.49 446 / 452 / 449 247.3 / 245.9 / 245.6

tick_lan −0.80 ms a tick (5.21 → 4.41, −15 %), with the same work (mobs, chunks a second). MSPT 30.77 → 30.43 on average, within the run-to-run noise of the whole tick.

Checks

  • cargo fmt --all --check, cargo clippy -p horizon-client --all-targets -- -D warnings: clean.
  • cargo test -p horizon-client --lib lan::: 36 passed (new: states_are_written_over_last_ticks_in_place).
  • Parity, on main + this + #1196 (one integration commit, desktop): tools/parity.py --changed origin/main ran 102 harnesses: 99 passed. save_roundtrip and world_reopen need a display (they launch the game; over SSH there is no Wayland: vscreen only). dedicated_server fails the same way on plain main (two extra block-update packets after a respawn, and a trade line that flakes).

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/1195 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/22/2026 **Status:** ✅ Merged **Merged:** 10/22/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/lan-entity-states` --- ### 📝 Commits (1) - [`83d0014`](https://github.com/horizon-rust/horizon/commit/83d001460cb9c973ab7ebb47aba028862f837008) LAN: write each tick's entity states over the last tick's ### 📊 Changes **4 files changed** (+149 additions, -93 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/lan.rs` (+46 -74) 📝 `crates/horizon-client/src/game/lan_attributes.rs` (+8 -10) 📝 `crates/horizon-client/src/game/lan_entities.rs` (+3 -8) 📝 `crates/horizon-client/src/lan/entity.rs` (+92 -1) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What `tick_lan` described every entity the guests track from scratch on every tick: for each mob, item and orb a new `String` for its type, new vectors for its entity data, equipment and attributes, all freed again at the end of the tick. On a 40-player server that was a few thousand allocations and frees per tick on the server thread. The states now stay in the LAN host between ticks (`lan::entity::States`). Each tick writes over the previous tick's states in place (`EntityState::reset`, then the same fields as before), so those strings and vectors keep their allocations. `mob_meta`, `mob_equipment` and `mob_attributes` write into the state's vectors instead of returning new ones. The rarer entities (boats, carts, stands, frames, paintings, projectiles, the dragon) are still built as before and pushed into the same list. ## Why Brief perf-server-13, target 1. Profile of a 40-bot dedicated server (ThinkPad i7-7500U, `perf record --call-graph lbr` on the server thread): `tick_lan` was 18–19 % of the server thread, of which rebuilding the states (`lan_entities` plus dropping last tick's `Vec<EntityState>`) was about 4.4 points, mostly `malloc`/`free`. ## Packets Unchanged. The states hold the same values in the same order as before, and everything the tracker sends is built from them (`Entities::tick` compares them with what it last sent, exactly as before). The new `States` buffer is tested: a reused slot is equal to a freshly built state and keeps its allocations. The `lan`, `tab_list`, `server_player_targets` and `online_mode` harnesses, which compare what a client receives against vanilla, pass. ## Numbers ThinkPad server (i7-7500U, 2 cores / 4 threads, `nice 19`), 40 bots on the desktop over Tailscale, `tools/server_bench.py --servers horizon --bots 40 --behaviour mixed --explore-speed 0.8 --warmup 120 --seconds 180 --nice 19`, seed 12345, view distance 10, `HORIZON_SPIKES=0` for the per-tick spans (averaged over the last 3,600 ticks). Release builds of main e730dc14 with and without this change, run interleaved (base, this, other, other, this, base, base, this, other): | run | MSPT avg | p95 | p99 | CPU ms/tick (server thread) | `tick_lan` ms/tick | mobs | chunks/s | |---|---:|---:|---:|---:|---:|---:|---:| | main 1 / 2 / 3 | 30.32 / 31.14 / 30.85 | 50.9 / 55.0 / 50.7 | 83.2 / 83.0 / 84.4 | 29.19 / 29.85 / 29.28 | 5.14 / 5.22 / 5.28 | 455 / 449 / 450 | 246.8 / 246.9 / 247.3 | | this 1 / 2 / 3 | 30.51 / 30.38 / 30.39 | 55.3 / 54.4 / 55.5 | 80.8 / 80.8 / 84.5 | 29.29 / 29.26 / 29.06 | **4.38 / 4.35 / 4.49** | 446 / 452 / 449 | 247.3 / 245.9 / 245.6 | `tick_lan` −0.80 ms a tick (5.21 → 4.41, −15 %), with the same work (mobs, chunks a second). MSPT 30.77 → 30.43 on average, within the run-to-run noise of the whole tick. ## Checks - `cargo fmt --all --check`, `cargo clippy -p horizon-client --all-targets -- -D warnings`: clean. - `cargo test -p horizon-client --lib lan::`: 36 passed (new: `states_are_written_over_last_ticks_in_place`). - Parity, on main + this + #1196 (one integration commit, desktop): `tools/parity.py --changed origin/main` ran 102 harnesses: 99 passed. `save_roundtrip` and `world_reopen` need a display (they launch the game; over SSH there is no Wayland: vscreen only). `dedicated_server` fails the same way on plain main (two extra block-update packets after a respawn, and a trade line that flakes). ## 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-03 04:09:19 +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#3409
No description provided.