[PR #972] [MERGED] Sculk: drop the blocks of every unloaded chunk in one pass #2954

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

📋 Pull Request Information

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

Base: main ← Head: perf/sculk-unload-once


📝 Commits (1)

  • cd99c1c Sculk: drop the blocks of every unloaded chunk in one pass

📊 Changes

1 file changed (+26 additions, -6 deletions)

View changed files

📝 crates/horizon-client/src/game/sculk.rs (+26 -6)

📄 Description

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

What

Every half second sculk_sync_index drops the sculk blocks (sensors, shriekers, catalysts) of the chunks that unloaded. It did that one chunk at a time, and each pass rebuilt the index's whole set:

for key in gone {
    self.sculk.index.retain(|p| (p.0 >> 4, p.2 >> 4) != key);   // and Index::retain rebuilt `set`
}

So the cost was (chunks unloaded) × (sculk blocks indexed). Now:

  • one retain over the index with the unloaded chunks in a set;
  • Index::retain filters its set in place instead of rebuilding it;
  • the arrived chunks are collected before they are scanned, instead of cloning the whole known set to iterate over.

Same blocks dropped, same order kept (Level.blockEntityTickers order), same chunks scanned in the same order.

Why

Brief perf-server-11, task 3 (the spikes). With the server thread no longer waiting for a core (#970), the worst tick left on the Mac mini with 40 explore bots was a single ~600 ms tick, all of it CPU, all of it tick_sculk_blocks: the moment the bots left and thousands of chunks unloaded at once, with a few thousand sculk blocks indexed after exploring deep dark terrain. The same loop ran every half second while exploring, for the chunks unloading behind the bots.

Numbers

Mac mini (M4 Pro, 14 threads, 80–90 % busy with other sessions), tools/server_bench.py --servers horizon --bots 40 --behaviour explore --explore-speed 5 --warmup 30 --seconds 120, HORIZON_SPIKES=0 (every tick logged with its wall and server-thread CPU time), first 400 ticks skipped, runs alternated. Builds on main with #915, #934, #914 and #927 plus the server-thread and heightmaps PRs (#970, #971); "after" adds this one.

40 bots, explore tick max (ms) worst tick's cause tick_sculk_blocks max / total tick wall p99 ticks > 50 ms MSPT avg / p95 / p99
before 1 583.4 tick_sculk_blocks 582.9 583 ms / 4.0 s 33.3 1 18.6 / 25.3 / 33.6
before 2 599.7 tick_sculk_blocks 599.3 599 ms / 3.7 s 30.2 1 17.7 / 23.1 / 28.1
after 1 38.3 tick_blocks 26.7 6 ms / 3.4 s 27.5 0 17.4 / 23.0 / 28.1
after 2 44.3 tick_lan 18.9 4 ms / 3.3 s 28.7 0 17.7 / 23.1 / 29.2

The two runs of the build with only the server-thread PR had the same ~600 ms tick (607.8 and 609.2 ms of tick_sculk_blocks). With this PR the worst tick of a 40-bot run is about 40 ms, and none goes over 50 ms.

Checks

  • cargo fmt --all --check, cargo clippy --workspace --all-targets -- -D warnings: clean.
  • cargo test -p horizon-client: 896 lib + 77 bin tests pass, with the new the_index_retains_in_order (order, membership and later inserts after a retain).
  • Integration commit ae52589e (origin/main c569bbe2 + this PR + perf-server-11's other PRs and #968): parity chunk_stage, dedicated_server, heightmap, lan, sculk, server_entities, server_world_gen, world_reopen: 8 passed, 0 failed. lan_e2e with and without --server-thread: nothing fails that doesn't fail on main on the same machine (see #968 for the checks that are flaky on a busy Mac mini).

Doesn't touch game.rs tick order (server-ticks-2).

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/972 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/19/2026 **Status:** ✅ Merged **Merged:** 10/19/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/sculk-unload-once` --- ### 📝 Commits (1) - [`cd99c1c`](https://github.com/horizon-rust/horizon/commit/cd99c1c683760003f8458401f0839cf3e1aa1d66) Sculk: drop the blocks of every unloaded chunk in one pass ### 📊 Changes **1 file changed** (+26 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/sculk.rs` (+26 -6) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What Every half second `sculk_sync_index` drops the sculk blocks (sensors, shriekers, catalysts) of the chunks that unloaded. It did that one chunk at a time, and each pass rebuilt the index's whole set: ```rust for key in gone { self.sculk.index.retain(|p| (p.0 >> 4, p.2 >> 4) != key); // and Index::retain rebuilt `set` } ``` So the cost was (chunks unloaded) × (sculk blocks indexed). Now: - one `retain` over the index with the unloaded chunks in a set; - `Index::retain` filters its set in place instead of rebuilding it; - the arrived chunks are collected before they are scanned, instead of cloning the whole `known` set to iterate over. Same blocks dropped, same order kept (`Level.blockEntityTickers` order), same chunks scanned in the same order. ## Why Brief perf-server-11, task 3 (the spikes). With the server thread no longer waiting for a core (#970), the worst tick left on the Mac mini with 40 explore bots was a single ~600 ms tick, all of it CPU, all of it `tick_sculk_blocks`: the moment the bots left and thousands of chunks unloaded at once, with a few thousand sculk blocks indexed after exploring deep dark terrain. The same loop ran every half second while exploring, for the chunks unloading behind the bots. ## Numbers Mac mini (M4 Pro, 14 threads, 80–90 % busy with other sessions), `tools/server_bench.py --servers horizon --bots 40 --behaviour explore --explore-speed 5 --warmup 30 --seconds 120`, `HORIZON_SPIKES=0` (every tick logged with its wall and server-thread CPU time), first 400 ticks skipped, runs alternated. Builds on main with #915, #934, #914 and #927 plus the server-thread and heightmaps PRs (#970, #971); "after" adds this one. | 40 bots, explore | tick max (ms) | worst tick's cause | `tick_sculk_blocks` max / total | tick wall p99 | ticks > 50 ms | MSPT avg / p95 / p99 | |---|---|---|---|---|---|---| | before 1 | 583.4 | `tick_sculk_blocks` 582.9 | 583 ms / 4.0 s | 33.3 | 1 | 18.6 / 25.3 / 33.6 | | before 2 | 599.7 | `tick_sculk_blocks` 599.3 | 599 ms / 3.7 s | 30.2 | 1 | 17.7 / 23.1 / 28.1 | | after 1 | **38.3** | `tick_blocks` 26.7 | **6 ms** / 3.4 s | 27.5 | 0 | 17.4 / 23.0 / 28.1 | | after 2 | **44.3** | `tick_lan` 18.9 | **4 ms** / 3.3 s | 28.7 | 0 | 17.7 / 23.1 / 29.2 | The two runs of the build with only the server-thread PR had the same ~600 ms tick (607.8 and 609.2 ms of `tick_sculk_blocks`). With this PR the worst tick of a 40-bot run is about 40 ms, and none goes over 50 ms. ## Checks - `cargo fmt --all --check`, `cargo clippy --workspace --all-targets -- -D warnings`: clean. - `cargo test -p horizon-client`: 896 lib + 77 bin tests pass, with the new `the_index_retains_in_order` (order, membership and later inserts after a retain). - Integration commit ae52589e (origin/main c569bbe2 + this PR + perf-server-11's other PRs and #968): parity `chunk_stage`, `dedicated_server`, `heightmap`, `lan`, `sculk`, `server_entities`, `server_world_gen`, `world_reopen`: 8 passed, 0 failed. lan_e2e with and without `--server-thread`: nothing fails that doesn't fail on main on the same machine (see #968 for the checks that are flaky on a busy Mac mini). Doesn't touch `game.rs` tick order (server-ticks-2). ## 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 16:00:22 +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#2954
No description provided.