[PR #269] [MERGED] Load worlds ~4.7x faster: stop copying the face visibility table per mesh job #2451

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

📋 Pull Request Information

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

Base: main ← Head: perf/worker-face-visibility


📝 Commits (3)

  • ed8f3d7 Keep each worker's face visibility table across mesh jobs
  • 50a1649 Pack small palettes without hashing
  • 213af61 status: report each streaming stage's work

📊 Changes

3 files changed (+67 additions, -37 deletions)

View changed files

📝 crates/horizon-client/src/game/control.rs (+2 -0)
📝 crates/horizon-client/src/streaming.rs (+33 -2)
📝 crates/horizon-core/src/paletted.rs (+32 -35)

📄 Description

A world now loads about 4.7× faster. At render distance 16, all 901 chunks are generated, decorated, lit and meshed in 9.5 s instead of 44.6 s.

What was slow

A sample of the client while it loads showed the 13 horizon-worker threads spending about half their busy time in Vec<VoxelShape>::clone and its drop. Every mesh job did context.tables.visibility.clone(), which deep-copies the whole FaceVisibility: one entry per block state, every face VoxelShape, and the occlusion cache. It then threw the copy away. Next on the list was SipHash in PalettedContainer::pack, which hashed all 4096 values of every section to build its palette.

  • Keep each worker's face visibility table across mesh jobs. Each worker owns one copy, like vanilla's per-thread occlusion cache, and clones a new one only when the mesh tables are replaced (resource reload). The cache is keyed by face shape ids, so reuse can't change any result.
  • Pack small palettes without hashing. pack now uses the same scan from_values already used, switching to a map past 16 distinct values. The palette order (first occurrence) and the output are unchanged.
  • status reports each streaming stage. A new streaming object (queued, generating, protos, decorating, finishing, lighting, meshing) and dirty_light show which stage a slow load waits on. That's how the numbers below were taken.

Measurements (Mac mini M4 Pro, 14 threads, offscreen, RD16, PerfBench seed 1234)

Time from open to all 901 chunks in the world, polled every 250 ms, interleaved runs:

run main this PR 1-min load average (main / PR)
1 42.8 s 10.4 s 63 / 51
2 46.0 s 8.8 s 44 / 35
3 45.1 s 9.2 s 62 / 43

The first chunk arrives after 3.4–6.0 s on both builds (world open). Sections meshed by the time the last chunk lands: about 110,000 on main, about 66,000 here. Fewer chunks arrive after their neighbours have already been meshed, so fewer sections get meshed again.

perf_bench.py's "loaded" figure (village 63–83 s here, against 107–122 s on main) waits for meshing to drop under 100 meshes/s. After the world is in, block updates keep remeshing at 1,500/s falling to about 60/s for about 150 s, with no light or mesh job queued. That tail is simulation (fluids settling and similar), not loading. It's tracked separately.

Same output

  • tools/parity.py section_mesh light: both pass on the Mac mini.
  • Screenshots after settling (animated textures off, chat faded) differ from main by 46,479 / 43,295 / 30,428 px. The pixels are clouds and scattered plant spots, the same pattern as main against itself (16,935–25,602 px in an earlier run). Terrain, light and geometry match.
  • cargo test -p horizon-client -p horizon-core (584 + core tests), cargo clippy -D warnings, cargo fmt --check pass.

Part of the benchmark work (features item 6).

🤖 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/269 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/15/2026 **Status:** ✅ Merged **Merged:** 10/15/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/worker-face-visibility` --- ### 📝 Commits (3) - [`ed8f3d7`](https://github.com/horizon-rust/horizon/commit/ed8f3d70b8528c1d5a5711303ba0ee1c635ec7f4) Keep each worker's face visibility table across mesh jobs - [`50a1649`](https://github.com/horizon-rust/horizon/commit/50a1649dea147ee3af1e2ee5cb6cf42635937fee) Pack small palettes without hashing - [`213af61`](https://github.com/horizon-rust/horizon/commit/213af61b92ba23ca7bfe1e947a3231332330981c) status: report each streaming stage's work ### 📊 Changes **3 files changed** (+67 additions, -37 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/control.rs` (+2 -0) 📝 `crates/horizon-client/src/streaming.rs` (+33 -2) 📝 `crates/horizon-core/src/paletted.rs` (+32 -35) </details> ### 📄 Description A world now loads about 4.7× faster. At render distance 16, all 901 chunks are generated, decorated, lit and meshed in **9.5 s** instead of **44.6 s**. ## What was slow A `sample` of the client while it loads showed the 13 `horizon-worker` threads spending about half their busy time in `Vec<VoxelShape>::clone` and its drop. Every mesh job did `context.tables.visibility.clone()`, which deep-copies the whole `FaceVisibility`: one entry per block state, every face `VoxelShape`, and the occlusion cache. It then threw the copy away. Next on the list was SipHash in `PalettedContainer::pack`, which hashed all 4096 values of every section to build its palette. - **Keep each worker's face visibility table across mesh jobs.** Each worker owns one copy, like vanilla's per-thread occlusion cache, and clones a new one only when the mesh tables are replaced (resource reload). The cache is keyed by face shape ids, so reuse can't change any result. - **Pack small palettes without hashing.** `pack` now uses the same scan `from_values` already used, switching to a map past 16 distinct values. The palette order (first occurrence) and the output are unchanged. - **`status` reports each streaming stage.** A new `streaming` object (queued, generating, protos, decorating, finishing, lighting, meshing) and `dirty_light` show which stage a slow load waits on. That's how the numbers below were taken. ## Measurements (Mac mini M4 Pro, 14 threads, offscreen, RD16, PerfBench seed 1234) Time from `open` to all 901 chunks in the world, polled every 250 ms, interleaved runs: | run | main | this PR | 1-min load average (main / PR) | |---|---|---|---| | 1 | 42.8 s | 10.4 s | 63 / 51 | | 2 | 46.0 s | 8.8 s | 44 / 35 | | 3 | 45.1 s | 9.2 s | 62 / 43 | The first chunk arrives after 3.4–6.0 s on both builds (world open). Sections meshed by the time the last chunk lands: about 110,000 on main, about 66,000 here. Fewer chunks arrive after their neighbours have already been meshed, so fewer sections get meshed again. `perf_bench.py`'s "loaded" figure (village 63–83 s here, against 107–122 s on main) waits for meshing to drop under 100 meshes/s. After the world is in, block updates keep remeshing at 1,500/s falling to about 60/s for about 150 s, with no light or mesh job queued. That tail is simulation (fluids settling and similar), not loading. It's tracked separately. ## Same output - `tools/parity.py section_mesh light`: both pass on the Mac mini. - Screenshots after settling (animated textures off, chat faded) differ from main by 46,479 / 43,295 / 30,428 px. The pixels are clouds and scattered plant spots, the same pattern as main against itself (16,935–25,602 px in an earlier run). Terrain, light and geometry match. - `cargo test -p horizon-client -p horizon-core` (584 + core tests), `cargo clippy -D warnings`, `cargo fmt --check` pass. Part of the benchmark work (features item 6). 🤖 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 15:56:17 +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#2451
No description provided.