[PR #239] [MERGED] perf(client): skip tick chunk synchronization when membership is unchanged #2428

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/239
Author: @rdbtCVS
Created: 10/14/2026
Status: ✅ Merged
Merged: 10/15/2026
Merged by: @ludovic111

Base: main ← Head: perf/chunk-membership-sync-20261014


📝 Commits (2)

  • 4cac0a1 perf(client): track structural chunk membership revisions
  • 2746802 perf(client): synchronize tick chunk membership only on changes

📊 Changes

6 files changed (+506 additions, -9 deletions)

View changed files

➕ crates/horizon-client/examples/tick_chunk_membership_bench.rs (+143 -0)
➕ crates/horizon-client/src/chunk_map.rs (+122 -0)
📝 crates/horizon-client/src/game.rs (+12 -8)
📝 crates/horizon-client/src/lib.rs (+2 -0)
➕ crates/horizon-client/src/tick_chunk_membership.rs (+226 -0)
📝 crates/horizon-client/src/world.rs (+1 -1)

📄 Description

Stable resident chunk membership currently rebuilds a HashSet and clones the previous set on every block tick. Cache the membership revision so these ticks return in O(1), and synchronize changed membership using the existing set plus added/removed scratch vectors. This also removes the full previous-set clone.

TickChunkMembership::clear() invalidates the revision as well as the keys, preserving re-registration after scheduler resets even when the world is unchanged. Process-wide ChunkMap tokens detect same-count key replacements and world-map replacement. Registration still runs before removal; existing saved-tick loading and consumption callbacks remain unchanged. Streaming and network writes go through the shared ChunkMap membership API.

This PR shares the exact support-only commit df1fac16351b89e17df0d9c1643decd18806b4b1 with #230 (ChunkMap, its lib module, and World.chunks type). It includes no streaming generation gate. Both independent PRs can reuse that common commit.

Validation:

  • CARGO_TARGET_DIR=/home/bob/Documents/horizon/target CARGO_INCREMENTAL=0 cargo test -p horizon-client --lib --profile fast tick_chunk_membership -- --nocapture: 2 tests pass. Compare old/new deltas through negative coordinates, additions/removals, same-count key replacements, same-key payload replacement, and world/scheduler resets. Exercise actual block/fluid Ticks with saved ticks, asserting equal scheduler contents after stable calls, unloads and resets.
  • CARGO_TARGET_DIR=/home/bob/Documents/horizon/target CARGO_INCREMENTAL=0 cargo test -p horizon-client --lib --profile fast chunk_map::tests -- --nocapture: shared membership token test passes.
  • CARGO_TARGET_DIR=/home/bob/Documents/horizon/target CARGO_INCREMENTAL=0 cargo clippy -p horizon-client --profile fast --lib --bin horizon-client --example tick_chunk_membership_bench -- -D warnings: passes, including compilation of the actual Game path.
  • CARGO_TARGET_DIR=/home/bob/Documents/horizon/target CARGO_INCREMENTAL=0 cargo fmt --all -- --check and git diff --check: pass.

Reproducible benchmark:

CARGO_TARGET_DIR=/home/bob/Documents/horizon/target CARGO_INCREMENTAL=0 cargo run -p horizon-client --profile fast --example tick_chunk_membership_bench

AMD Ryzen 5 5600X, Linux x86_64, rustc 1.99.0, optimized fast profile. Synthetic 1,089 resident keys spanning negative coordinates; shared empty chunk payloads because this path reads keys only. 64 warmup calls, 9 samples, alternating baseline/optimized measurement order, medians with black_box and identical registration/removal count assertions on every sample.

Scenario Before ns/sync After ns/sync Ratio Iterations/sample
Stable membership 29,421.7 1.9 15,129.96x 10,000
One-key same-count replacement 29,175.9 17,906.3 1.63x 2,000
Whole disjoint map replacement 28,866.8 28,133.6 1.03x 1,000

The benchmark compares the original collect/clone/difference algorithm with the production membership helper called by Game. It excludes saved-tick registration callback work, rendering and full gameplay; this is not an FPS claim. One-key measurements include identical remove/insert map mutations. Full replacement is close to parity because all keys must be checked and changed. The cache retains its key set and delta-vector capacities (up to peak membership changes) in exchange for avoiding per-tick set allocation; no full previous-set copy is retained.


🔄 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/239 **Author:** [@rdbtCVS](https://github.com/rdbtCVS) **Created:** 10/14/2026 **Status:** ✅ Merged **Merged:** 10/15/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/chunk-membership-sync-20261014` --- ### 📝 Commits (2) - [`4cac0a1`](https://github.com/horizon-rust/horizon/commit/4cac0a13cd8cebdad0640c0107b2d2f6d4a14f76) perf(client): track structural chunk membership revisions - [`2746802`](https://github.com/horizon-rust/horizon/commit/27468021523a8cb69eaf27819670f117b6c5e63f) perf(client): synchronize tick chunk membership only on changes ### 📊 Changes **6 files changed** (+506 additions, -9 deletions) <details> <summary>View changed files</summary> ➕ `crates/horizon-client/examples/tick_chunk_membership_bench.rs` (+143 -0) ➕ `crates/horizon-client/src/chunk_map.rs` (+122 -0) 📝 `crates/horizon-client/src/game.rs` (+12 -8) 📝 `crates/horizon-client/src/lib.rs` (+2 -0) ➕ `crates/horizon-client/src/tick_chunk_membership.rs` (+226 -0) 📝 `crates/horizon-client/src/world.rs` (+1 -1) </details> ### 📄 Description Stable resident chunk membership currently rebuilds a HashSet and clones the previous set on every block tick. Cache the membership revision so these ticks return in O(1), and synchronize changed membership using the existing set plus added/removed scratch vectors. This also removes the full previous-set clone. `TickChunkMembership::clear()` invalidates the revision as well as the keys, preserving re-registration after scheduler resets even when the world is unchanged. Process-wide ChunkMap tokens detect same-count key replacements and world-map replacement. Registration still runs before removal; existing saved-tick loading and consumption callbacks remain unchanged. Streaming and network writes go through the shared ChunkMap membership API. This PR shares the exact support-only commit `df1fac16351b89e17df0d9c1643decd18806b4b1` with #230 (ChunkMap, its lib module, and World.chunks type). It includes no streaming generation gate. Both independent PRs can reuse that common commit. Validation: - `CARGO_TARGET_DIR=/home/bob/Documents/horizon/target CARGO_INCREMENTAL=0 cargo test -p horizon-client --lib --profile fast tick_chunk_membership -- --nocapture`: 2 tests pass. Compare old/new deltas through negative coordinates, additions/removals, same-count key replacements, same-key payload replacement, and world/scheduler resets. Exercise actual block/fluid Ticks with saved ticks, asserting equal scheduler contents after stable calls, unloads and resets. - `CARGO_TARGET_DIR=/home/bob/Documents/horizon/target CARGO_INCREMENTAL=0 cargo test -p horizon-client --lib --profile fast chunk_map::tests -- --nocapture`: shared membership token test passes. - `CARGO_TARGET_DIR=/home/bob/Documents/horizon/target CARGO_INCREMENTAL=0 cargo clippy -p horizon-client --profile fast --lib --bin horizon-client --example tick_chunk_membership_bench -- -D warnings`: passes, including compilation of the actual Game path. - `CARGO_TARGET_DIR=/home/bob/Documents/horizon/target CARGO_INCREMENTAL=0 cargo fmt --all -- --check` and `git diff --check`: pass. Reproducible benchmark: ```sh CARGO_TARGET_DIR=/home/bob/Documents/horizon/target CARGO_INCREMENTAL=0 cargo run -p horizon-client --profile fast --example tick_chunk_membership_bench ``` AMD Ryzen 5 5600X, Linux x86_64, rustc 1.99.0, optimized fast profile. Synthetic 1,089 resident keys spanning negative coordinates; shared empty chunk payloads because this path reads keys only. 64 warmup calls, 9 samples, alternating baseline/optimized measurement order, medians with black_box and identical registration/removal count assertions on every sample. | Scenario | Before ns/sync | After ns/sync | Ratio | Iterations/sample | | --- | ---: | ---: | ---: | ---: | | Stable membership | 29,421.7 | 1.9 | 15,129.96x | 10,000 | | One-key same-count replacement | 29,175.9 | 17,906.3 | 1.63x | 2,000 | | Whole disjoint map replacement | 28,866.8 | 28,133.6 | 1.03x | 1,000 | The benchmark compares the original collect/clone/difference algorithm with the production membership helper called by Game. It excludes saved-tick registration callback work, rendering and full gameplay; this is not an FPS claim. One-key measurements include identical remove/insert map mutations. Full replacement is close to parity because all keys must be checked and changed. The cache retains its key set and delta-vector capacities (up to peak membership changes) in exchange for avoiding per-tick set allocation; no full previous-set copy is retained. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 15:56:01 +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#2428
No description provided.