[PR #4744] [MERGED] Fluids: spread without cloning shapes or locking per step #5823

Closed
opened 2026-11-03 05:15:14 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4744
Author: @apeirs
Created: 10/30/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @rdbtCVS

Base: main ← Head: fluid-spread-no-clones


📝 Commits (1)

  • bcb2087 Fluids: spread without cloning shapes or locking per step

📊 Changes

3 files changed (+66 additions, -47 deletions)

View changed files

📝 crates/horizon-core/src/geometry/shape.rs (+12 -5)
📝 crates/horizon-world/src/level/fluids.rs (+52 -40)
📝 crates/horizon-world/src/level/mod.rs (+2 -2)

📄 Description

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

What and why

Fixes #4743. FlowingFluid.spread's slope search calls can_pass_through_wall for every step. That function cloned up to four VoxelShapes per call (five Arc counts each; the shared block and empty shapes' counters are hit by every thread, generation workers included) and locked the global occlusion_cache mutex once or twice. Fluid ticks cost ~10× a block tick, and fresh terrain schedules many of them.

  • collision_or_empty borrows the shape (&VoxelShape; Behaviours::collision_shape already returns a reference) instead of cloning it.
  • Identity checks use VoxelShape::is_block() (existing) and a new VoxelShape::is_empty_identity() (with empty_ref()), the same same_identity comparisons without the clones. merged_face_occludes uses is_block() too.
  • occlusion_cache is an RwLock: concurrent hits no longer serialize.
  • SpreadContext's two caches are flat arrays around the origin (11×11: the slope search goes at most 4 steps past the first), no hashing or allocation; a position outside them is read uncached.

Same comparisons and the same cached values, so the same results; only the cost changes.

Kind

  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • perf: faster, or less memory
  • feature: something new for players (listed under New in the release notes)
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Vanilla reference

FlowingFluid.canPassThroughWall, FlowingFluid.getSpread / getSlopeDistance with SpreadContext: unchanged logic; vanilla also caches states and holes per spread (in Short2ObjectMap / Short2BooleanMap). The fluid harnesses (fluid_flow, fluid, fluid_shape, ...) are CI's to confirm; I could not run parity locally (no vanilla data on this machine).

Measurements

Instrumented builds of 587f81f (fast profile) timing every scheduled tick on the server thread; i7-11850H laptop, a copied survival world, render distance 24, a fixed 20 s spectator flight at 50 blocks/s through new terrain; three rounds, builds alternating. A = main, B = no clones + RwLock, C = this PR (B + array caches). Block ticks (untouched) are the control.

block tick fluid tick scheduled-tick ms in server ticks with ≥ 2 ms of it
A (main) 1.03 / 1.15 / 1.08 µs 12.6 / 12.2 / 11.2 µs 322 / 311 / 368
B 1.08 / 1.25 / 1.14 µs 5.8 / 5.1 / 6.8 µs 81 / 57 / 102
C (this PR) 1.20 / 1.10 / 1.04 µs 4.9 / 3.1 / 3.5 µs 79 / 22 / 35

About 3× cheaper fluid ticks, and server ticks with ≥ 2 ms of scheduled work went from 128 / 112 / 142 to 108 / 40 / 38 per flight.

Self-check

pr_ready (tools/pr_ready.py --quick on arch, against origin/main at c822f6eb8, 5 min 4 s)

Check Result
Scope ✅ 3 files, +66 −47
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 481 passed (1 min 1 s)
rustfmt ✅ (12 s)
clippy ✅ (2 min 15 s)
tests: horizon-core, horizon-world ✅ 405 passed (56 s)
doc tests ✅ 0 passed (40 s)
content root tests ➖ content root untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ not run (--quick): CI's parity job picks the affected harnesses
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🤖 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/4744 **Author:** [@apeirs](https://github.com/apeirs) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@rdbtCVS](https://github.com/rdbtCVS) **Base:** `main` ← **Head:** `fluid-spread-no-clones` --- ### 📝 Commits (1) - [`bcb2087`](https://github.com/horizon-rust/horizon/commit/bcb2087d2f5b7c7a560227e604f1755d8bb79e90) Fluids: spread without cloning shapes or locking per step ### 📊 Changes **3 files changed** (+66 additions, -47 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-core/src/geometry/shape.rs` (+12 -5) 📝 `crates/horizon-world/src/level/fluids.rs` (+52 -40) 📝 `crates/horizon-world/src/level/mod.rs` (+2 -2) </details> ### 📄 Description > 🤖 Opened by apeirs's AI agent (Claude Code, Claude Opus 5.5), not by apeirs personally. ## What and why Fixes #4743. `FlowingFluid.spread`'s slope search calls `can_pass_through_wall` for every step. That function cloned up to four `VoxelShape`s per call (five `Arc` counts each; the shared block and empty shapes' counters are hit by every thread, generation workers included) and locked the global `occlusion_cache` mutex once or twice. Fluid ticks cost ~10× a block tick, and fresh terrain schedules many of them. - `collision_or_empty` borrows the shape (`&VoxelShape`; `Behaviours::collision_shape` already returns a reference) instead of cloning it. - Identity checks use `VoxelShape::is_block()` (existing) and a new `VoxelShape::is_empty_identity()` (with `empty_ref()`), the same `same_identity` comparisons without the clones. `merged_face_occludes` uses `is_block()` too. - `occlusion_cache` is an `RwLock`: concurrent hits no longer serialize. - `SpreadContext`'s two caches are flat arrays around the origin (11×11: the slope search goes at most 4 steps past the first), no hashing or allocation; a position outside them is read uncached. Same comparisons and the same cached values, so the same results; only the cost changes. ## Kind - [ ] parity: Horizon now does what vanilla 26.3 does - [ ] bug: a crash or a breakage - [x] perf: faster, or less memory - [ ] feature: something new for players (listed under New in the release notes) - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference `FlowingFluid.canPassThroughWall`, `FlowingFluid.getSpread` / `getSlopeDistance` with `SpreadContext`: unchanged logic; vanilla also caches states and holes per spread (in `Short2ObjectMap` / `Short2BooleanMap`). The fluid harnesses (`fluid_flow`, `fluid`, `fluid_shape`, ...) are CI's to confirm; I could not run parity locally (no vanilla data on this machine). ## Measurements Instrumented builds of 587f81f (`fast` profile) timing every scheduled tick on the server thread; i7-11850H laptop, a copied survival world, render distance 24, a fixed 20 s spectator flight at 50 blocks/s through new terrain; three rounds, builds alternating. A = main, B = no clones + RwLock, C = this PR (B + array caches). Block ticks (untouched) are the control. | | block tick | fluid tick | scheduled-tick ms in server ticks with ≥ 2 ms of it | |---|---|---|---| | A (main) | 1.03 / 1.15 / 1.08 µs | 12.6 / 12.2 / 11.2 µs | 322 / 311 / 368 | | B | 1.08 / 1.25 / 1.14 µs | 5.8 / 5.1 / 6.8 µs | 81 / 57 / 102 | | C (this PR) | 1.20 / 1.10 / 1.04 µs | 4.9 / 3.1 / 3.5 µs | 79 / 22 / 35 | About 3× cheaper fluid ticks, and server ticks with ≥ 2 ms of scheduled work went from 128 / 112 / 142 to 108 / 40 / 38 per flight. ## Self-check **pr_ready** (`tools/pr_ready.py --quick` on arch, against origin/main at c822f6eb8, 5 min 4 s) | Check | Result | | --- | --- | | Scope | ✅ 3 files, +66 −47 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 481 passed (1 min 1 s) | | rustfmt | ✅ (12 s) | | clippy | ✅ (2 min 15 s) | | tests: horizon-core, horizon-world | ✅ 405 passed (56 s) | | doc tests | ✅ 0 passed (40 s) | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ not run (--quick): CI's parity job picks the affected harnesses | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | 🤖 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 05:15:14 +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#5823
No description provided.