[GH-ISSUE #5038] Server thread: building light views converts generated chunks block by block (~28% of the thread while flying) #1528

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

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

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, a large share of the integrated server thread goes to VanillaTerrain::column, converting generated proto chunks into columns. A CPU profile (pprof inside the game, 30 s of spectator flight at 50 blocks/s, render distance 24) put 27.7 % of the server thread under Streaming::light_region → VanillaTerrain::light_view → VanillaTerrain::column, half of it in ProtoChunk::block.

Why: column reads every block of a generated section one call at a time (chunk.block(x, y, z): section lookup, coordinates, palette read; ~98k calls a chunk), then repacks it with Section::from_blocks. Light views for the ring past the view distance are built on the server thread, and while the player moves that ring keeps advancing.

Proposed fix: read a whole generated section in one pass (unpack the paletted storage word by word, map through the palette), with the per-block loop kept for a partly generated section. Same values, same packing.

PR with the fix follows.

Originally created by @apeirs on GitHub (Oct 31, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/5038 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, a large share of the integrated server thread goes to `VanillaTerrain::column`, converting generated proto chunks into columns. A CPU profile (pprof inside the game, 30 s of spectator flight at 50 blocks/s, render distance 24) put **27.7 % of the server thread** under `Streaming::light_region` → `VanillaTerrain::light_view` → `VanillaTerrain::column`, half of it in `ProtoChunk::block`. **Why:** `column` reads every block of a generated section one call at a time (`chunk.block(x, y, z)`: section lookup, coordinates, palette read; ~98k calls a chunk), then repacks it with `Section::from_blocks`. Light views for the ring past the view distance are built on the server thread, and while the player moves that ring keeps advancing. **Proposed fix:** read a whole generated section in one pass (unpack the paletted storage word by word, map through the palette), with the per-block loop kept for a partly generated section. Same values, same packing. PR with the fix follows.
Author
Owner

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

/claim

🤖 Agent: fix verified, PR follows.

<!-- gh-comment-id:6541613270 --> @apeirs commented on GitHub (Oct 31, 2026): /claim 🤖 Agent: fix verified, 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#1528
No description provided.