[GH-ISSUE #4743] Fluid ticks cost ~10x a block tick: spread's slope search clones shapes and locks a global mutex per step #1432

Closed
opened 2026-11-02 15:46:54 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @apeirs on GitHub (Oct 30, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/4743

Originally assigned to: @apeirs on GitHub.

🤖 Filed by apeirs's AI agent (Claude Code, Claude Opus 5.5), not by apeirs personally.

What happens: flying into new terrain, the integrated server's ticks run long, and a large share is scheduled fluid ticks (water and lava settling in freshly generated chunks). A fluid tick costs about 10× a block tick: measured on the server thread, about 12 µs each against about 1.1 µs, with up to ~1,100 fluid ticks in one server tick.

Where the time goes: nearly all of it is FlowingFluid.spread (Sim::spread → spread_targets → slope_distance). Every step of the slope search calls can_pass_through_wall, which:

  • clones up to four VoxelShapes per call (collision_or_empty twice, plus VoxelShape::block() and VoxelShape::empty()). Each clone is five Arc increments and decrements, and the shared block and empty shapes' counters are touched by every thread at once, generation workers included;
  • locks the global occlusion_cache Mutex once on a hit and twice on a miss.

SpreadContext also keeps its two per-spread caches in HashMap<i16, _> (SipHash, allocating on insert) for at most an 11×11 area.

Measured how (instrumented build of 587f81f, HORIZON_SPIKES, a fixed 20 s spectator flight at 50 blocks/s through new terrain in a copied survival world; i7-11850H laptop): fluid ticks spent ~250 ms in spread against ~6 ms in new_liquid and ~0 in setting blocks.

PR with the fix and an A/B follows.

Originally created by @apeirs on GitHub (Oct 30, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/4743 Originally assigned to: @apeirs on GitHub. > 🤖 Filed by apeirs's AI agent (Claude Code, Claude Opus 5.5), not by apeirs personally. **What happens:** flying into new terrain, the integrated server's ticks run long, and a large share is scheduled fluid ticks (water and lava settling in freshly generated chunks). A fluid tick costs about **10× a block tick**: measured on the server thread, about 12 µs each against about 1.1 µs, with up to ~1,100 fluid ticks in one server tick. **Where the time goes:** nearly all of it is `FlowingFluid.spread` (`Sim::spread` → `spread_targets` → `slope_distance`). Every step of the slope search calls `can_pass_through_wall`, which: - clones up to four `VoxelShape`s per call (`collision_or_empty` twice, plus `VoxelShape::block()` and `VoxelShape::empty()`). Each clone is five `Arc` increments and decrements, and the shared block and empty shapes' counters are touched by every thread at once, generation workers included; - locks the global `occlusion_cache` `Mutex` once on a hit and twice on a miss. `SpreadContext` also keeps its two per-spread caches in `HashMap<i16, _>` (SipHash, allocating on insert) for at most an 11×11 area. Measured how (instrumented build of 587f81f, `HORIZON_SPIKES`, a fixed 20 s spectator flight at 50 blocks/s through new terrain in a copied survival world; i7-11850H laptop): fluid ticks spent ~250 ms in `spread` against ~6 ms in `new_liquid` and ~0 in setting blocks. PR with the fix and an A/B follows.
Author
Owner

@apeirs commented on GitHub (Oct 30, 2026):

/claim

🤖 Agent: fix and A/B ready, PR follows.

<!-- gh-comment-id:6535264108 --> @apeirs commented on GitHub (Oct 30, 2026): /claim 🤖 Agent: fix and A/B ready, PR follows.
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#1432
No description provided.