[PR #7686] [MERGED] perf(render): spectator post chains compile in the background #7761

Closed
opened 2026-11-03 07:23:50 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7686
Author: @ludovic111
Created: 11/2/2026
Status: ✅ Merged
Merged: 11/2/2026
Merged by: @ludovic111

Base: main ← Head: perf/post-chain-preload


📝 Commits (1)

  • a6f0187 perf(render): spectator post chains compile in the background

📊 Changes

2 files changed (+216 additions, -48 deletions)

View changed files

📝 crates/horizon-client-render/src/gfx.rs (+24 -14)
📝 crates/horizon-client-render/src/post_chain.rs (+192 -34)

📄 Description

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

What

The first frame through a creeper's, spider's or enderman's eyes (spectator mode) loaded its post chain and compiled its pipelines inside that frame. On Metal the render thread waits for the system's shader compiler, so the frame used little CPU but a lot of wall time. With Metal's shader cache cold (the machine's first play, or shaders that changed), that froze the game. The first spectate on the Mac mini froze for 918 ms (creeper), 306 ms (spider) and 101 ms (enderman). The render thread used only 4.7 ms of CPU in the 918 ms frame.

PostEffects::preload now loads the three spectator chains (SPECTATOR_CHAINS: creeper, spider, invert) and compiles their pipelines for the frame's format, on a thread of its own, from the first frame in a world. apply collects what has arrived. A chain still compiling is left out of the frame (the spectator view shows without its effect for that short time) instead of being compiled there.

Chain loading only needs the resources root, so load, translated_pass, standin_pass and image take it instead of &self. Other chains (pack effects, end_of_frame) still load on first use as before.

A/B

RD 12, 3 alternated pairs on the Mac mini. Each run spectates a creeper, a spider, an enderman and a cave spider. Each run also uses a resources root whose post vertex shader carries a never-true branch with a unique constant, so Metal compiles every run cold. Metal's shader cache is per user and keyed by source; I didn't clear it because other sessions use it.

build worst frame (creeper) worst frame (spider) max 0.1% low
main 140.2 / 67.1 / 72.2 ms 7.5 / 11.2 / 25.3 ms 67–140 ms 88.6 / 118.9 / 163.1
PR 6.5 / 4.4 / 2.7 ms 6.4 / 6.9 / 2.5 ms 5.7–7.8 ms 192.1 / 197.3 / 277.1

Only the vertex shader is cold in these runs. A fully cold first play (fragment shaders too) was the 918 ms above.

Test

a_preloaded_chain_arrives_compiled: a chain with its own GLSL (the setup of a_chain_runs_its_own_glsl, now shared as own_glsl) arrives from preload with a pipeline for the frame's format in every pass. It then draws the same pixels as a chain loaded in its frame.

pr_ready

pr_ready (tools/pr_ready.py --quick on playhorizon, against origin/main at 7cc36d34c, 6 min 9 s)

Check Result
Scope ✅ 2 files, +216 −48
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 614 passed (1 min 8 s)
rustfmt ✅ (14 s)
clippy ✅ (2 min 45 s)
tests: horizon-client-render ❌ failed (1 min 19 s)
doc tests ✅ 0 passed (2 s)
content root tests ➖ content root untouched
mod API up to date ➖ native hooks untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 140 affected, to run in CI (--quick): ambient_sound, anvil_turtle_egg, armor_stand_frost, armor_stand_turtle_egg, arrow, arrow_wind_charge, audio_attributes, auto_jump, block_entity_anim, block_entity_render, block_entity_tickers, block_particles and 128 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

The ❌ is the known llvmpipe SIGSEGV of horizon-client-render's lib tests in parallel. On the same checkout, cargo test -p horizon-client-render --lib -- --test-threads=1 gives 1170 passed, 0 failed.

🤖 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/7686 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/post-chain-preload` --- ### 📝 Commits (1) - [`a6f0187`](https://github.com/horizon-rust/horizon/commit/a6f01872071728d8bd9bb92a57ac7dab1fd95b1f) perf(render): spectator post chains compile in the background ### 📊 Changes **2 files changed** (+216 additions, -48 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/gfx.rs` (+24 -14) 📝 `crates/horizon-client-render/src/post_chain.rs` (+192 -34) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What The first frame through a creeper's, spider's or enderman's eyes (spectator mode) loaded its post chain and compiled its pipelines inside that frame. On Metal the render thread waits for the system's shader compiler, so the frame used little CPU but a lot of wall time. With Metal's shader cache cold (the machine's first play, or shaders that changed), that froze the game. The first spectate on the Mac mini froze for **918 ms** (creeper), **306 ms** (spider) and **101 ms** (enderman). The render thread used only 4.7 ms of CPU in the 918 ms frame. `PostEffects::preload` now loads the three spectator chains (`SPECTATOR_CHAINS`: creeper, spider, invert) and compiles their pipelines for the frame's format, on a thread of its own, from the first frame in a world. `apply` collects what has arrived. A chain still compiling is left out of the frame (the spectator view shows without its effect for that short time) instead of being compiled there. Chain loading only needs the resources root, so `load`, `translated_pass`, `standin_pass` and `image` take it instead of `&self`. Other chains (pack effects, `end_of_frame`) still load on first use as before. ## A/B RD 12, 3 alternated pairs on the Mac mini. Each run spectates a creeper, a spider, an enderman and a cave spider. Each run also uses a resources root whose post vertex shader carries a never-true branch with a unique constant, so Metal compiles every run cold. Metal's shader cache is per user and keyed by source; I didn't clear it because other sessions use it. | build | worst frame (creeper) | worst frame (spider) | max | 0.1% low | |---|---|---|---|---| | main | 140.2 / 67.1 / 72.2 ms | 7.5 / 11.2 / 25.3 ms | 67–140 ms | 88.6 / 118.9 / 163.1 | | PR | 6.5 / 4.4 / 2.7 ms | 6.4 / 6.9 / 2.5 ms | 5.7–7.8 ms | 192.1 / 197.3 / 277.1 | Only the vertex shader is cold in these runs. A fully cold first play (fragment shaders too) was the 918 ms above. ## Test `a_preloaded_chain_arrives_compiled`: a chain with its own GLSL (the setup of `a_chain_runs_its_own_glsl`, now shared as `own_glsl`) arrives from `preload` with a pipeline for the frame's format in every pass. It then draws the same pixels as a chain loaded in its frame. ## pr_ready **pr_ready** (`tools/pr_ready.py --quick` on playhorizon, against origin/main at 7cc36d34c, 6 min 9 s) | Check | Result | | --- | --- | | Scope | ✅ 2 files, +216 −48 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 614 passed (1 min 8 s) | | rustfmt | ✅ (14 s) | | clippy | ✅ (2 min 45 s) | | tests: horizon-client-render | ❌ failed (1 min 19 s) | | doc tests | ✅ 0 passed (2 s) | | content root tests | ➖ content root untouched | | mod API up to date | ➖ native hooks untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 140 affected, to run in CI (--quick): ambient_sound, anvil_turtle_egg, armor_stand_frost, armor_stand_turtle_egg, arrow, arrow_wind_charge, audio_attributes, auto_jump, block_entity_anim, block_entity_render, block_entity_tickers, block_particles and 128 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | The ❌ is the known llvmpipe SIGSEGV of `horizon-client-render`'s lib tests in parallel. On the same checkout, `cargo test -p horizon-client-render --lib -- --test-threads=1` gives 1170 passed, 0 failed. 🤖 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 07:23:50 +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#7761
No description provided.