[PR #1747] [MERGED] Meshing: look up a block's baked models by index, not by model name #3739

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

📋 Pull Request Information

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

Base: main ← Head: perf/mesh-model-lookup


📝 Commits (1)

  • 4e3e038 Meshing: look up a block's baked models by index, not by model name

📊 Changes

4 files changed (+286 additions, -48 deletions)

View changed files

📝 crates/horizon-assets/src/blockstate/choice.rs (+50 -15)
➕ crates/horizon-client/examples/chunk_load_bench.rs (+168 -0)
📝 crates/horizon-client/src/mesher.rs (+9 -5)
📝 crates/horizon-client/src/models/catalog.rs (+59 -28)

📄 Description

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

What

The mesher asked the model catalog for each block's models through a state BTreeMap, a Vec of the chosen
variants, then per variant a clone of the model name and a string-keyed BTreeMap lookup, collected into a second
Vec: two allocations, a String clone and string compares for every block drawn. On generated terrain that was
about a fifth of Mesher::tesselate.

  • CompiledChoices (horizon-assets) is generic over what a variant stands for and gets map and for_each;
    collect is for_each pushing into a Vec. The random draws are the same calls in the same order.
  • StateModels resolves every variant to its baked model's index once, at load, keeps states in a Vec by id and
    the baked models in a Vec with their variant. collect/collect_seeded keep their signatures (minecarts, the
    model library bench); the mesher uses the new models_at, which fills one reused list per section.
  • examples/chunk_load_bench.rs (new): generates and lights real terrain around the perf_bench village with the
    vanilla generator and the game's worker pool, then meshes every section of the inner columns on one thread, timing
    Mesher::mesh in thread CPU time and printing a checksum of the meshes, so an A/B pair of builds shows they made
    the same meshes.

Why

perf-next-1 measured where loading time goes (horizon-parity/perf-status.md). Meshing is 6–8 % of single-player
chunk loading (one job per section: 55,243 jobs for 55,198 uploads at RD 16, counted with a temporary counter), but
it is all of a client's own cost on a server or as a LAN guest, and every block change remeshes. This was its
largest single waste.

Numbers

chunk_load_bench .local/horizon-client/26.3 --radius 6 --threads 6 --rounds 8 (2,328 sections, 1,429,396
vertices), main and this branch alternated three times each, best of 8 rounds per run:

Machine main µs/section this PR checksum (both)
Mac mini M4 Pro (load avg ~60, other agents) 43.9 / 46.6 / 46.9 34.5 / 36.7 / 35.0 (−23 %) 20c76cb5e1fb3d49
ThinkPad i5-7200U (idle) 114.0 / 113.9 / 114.4 99.7 / 99.7 / 100.0 (−13 %)¹ 20c76cb5e1fb3d49

¹ That ThinkPad run still hashed the meshes inside the timed loop (an earlier version of the example), which adds
the same fixed cost to both sides, so the real gain there is larger than shown.

No rendering change: the meshes are byte-identical (checksum above), and the section-mesh parity harness and the
streaming mesh tests are in the self-check below. Single-player loading time moves by about 1–2 %, inside the
benchmark's noise, so no perf_bench before/after is claimed.

Self-check

Full run before rebasing (on 947d65e64; its only failure was a clippy unnecessary_cast in the new example, fixed since):

pr_ready (tools/pr_ready.py on ludovics-mac-mini, against origin/main at 947d65e64, 80 min 22 s)

Check Result
Scope ✅ 4 files, +286 −48
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ➖ no Python change
rustfmt ✅ (6 s)
clippy ❌ failed (52 s)
tests: horizon-assets, horizon-client ✅ 1209 passed (5 min 15 s)
doc tests ✅ 0 passed (2 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ✅ 117 affected, 117 passed (72 min 48 s)
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

After rebasing onto 4a675206b:

pr_ready (tools/pr_ready.py --quick on ludovics-mac-mini, against origin/main at 4a675206b, 8 min 49 s)

Check Result
Scope ✅ 4 files, +286 −48
Cargo.lock ✅ unchanged
Public tree ✅ (1 s)
Python tests ➖ no Python change
rustfmt ✅ (7 s)
clippy ✅ (28 s)
tests: horizon-assets, horizon-client ✅ 1210 passed (7 min 56 s)
doc tests ✅ 0 passed (4 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 114 affected, to run in CI (--quick): ambient_sound, arrow, audio_attributes, auto_jump, block_entity_anim, block_entity_render, block_entity_tickers, block_particles, block_removal, block_transformer, blockstate_binding, blockstate_model and 102 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

Needs Ludovic

Nothing. No label: a speed-up players don't see as a feature.

🤖 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/1747 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/25/2026 **Status:** ✅ Merged **Merged:** 10/25/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/mesh-model-lookup` --- ### 📝 Commits (1) - [`4e3e038`](https://github.com/horizon-rust/horizon/commit/4e3e038c804d877c53e403b2ed46a9d18dac2f07) Meshing: look up a block's baked models by index, not by model name ### 📊 Changes **4 files changed** (+286 additions, -48 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-assets/src/blockstate/choice.rs` (+50 -15) ➕ `crates/horizon-client/examples/chunk_load_bench.rs` (+168 -0) 📝 `crates/horizon-client/src/mesher.rs` (+9 -5) 📝 `crates/horizon-client/src/models/catalog.rs` (+59 -28) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What The mesher asked the model catalog for each block's models through a state `BTreeMap`, a `Vec` of the chosen variants, then per variant a clone of the model name and a string-keyed `BTreeMap` lookup, collected into a second `Vec`: two allocations, a `String` clone and string compares for every block drawn. On generated terrain that was about a fifth of `Mesher::tesselate`. - `CompiledChoices` (horizon-assets) is generic over what a variant stands for and gets `map` and `for_each`; `collect` is `for_each` pushing into a `Vec`. The random draws are the same calls in the same order. - `StateModels` resolves every variant to its baked model's index once, at load, keeps states in a `Vec` by id and the baked models in a `Vec` with their variant. `collect`/`collect_seeded` keep their signatures (minecarts, the model library bench); the mesher uses the new `models_at`, which fills one reused list per section. - `examples/chunk_load_bench.rs` (new): generates and lights real terrain around the perf_bench village with the vanilla generator and the game's worker pool, then meshes every section of the inner columns on one thread, timing `Mesher::mesh` in thread CPU time and printing a checksum of the meshes, so an A/B pair of builds shows they made the same meshes. ## Why perf-next-1 measured where loading time goes (`horizon-parity/perf-status.md`). Meshing is 6–8 % of single-player chunk loading (one job per section: 55,243 jobs for 55,198 uploads at RD 16, counted with a temporary counter), but it is all of a client's own cost on a server or as a LAN guest, and every block change remeshes. This was its largest single waste. ## Numbers `chunk_load_bench .local/horizon-client/26.3 --radius 6 --threads 6 --rounds 8` (2,328 sections, 1,429,396 vertices), main and this branch alternated three times each, best of 8 rounds per run: | Machine | main µs/section | this PR | checksum (both) | |---|---|---|---| | Mac mini M4 Pro (load avg ~60, other agents) | 43.9 / 46.6 / 46.9 | 34.5 / 36.7 / 35.0 (**−23 %**) | `20c76cb5e1fb3d49` | | ThinkPad i5-7200U (idle) | 114.0 / 113.9 / 114.4 | 99.7 / 99.7 / 100.0 (**−13 %**)¹ | `20c76cb5e1fb3d49` | ¹ That ThinkPad run still hashed the meshes inside the timed loop (an earlier version of the example), which adds the same fixed cost to both sides, so the real gain there is larger than shown. No rendering change: the meshes are byte-identical (checksum above), and the section-mesh parity harness and the streaming mesh tests are in the self-check below. Single-player loading time moves by about 1–2 %, inside the benchmark's noise, so no perf_bench before/after is claimed. ## Self-check Full run before rebasing (on 947d65e64; its only failure was a clippy `unnecessary_cast` in the new example, fixed since): **pr_ready** (`tools/pr_ready.py` on ludovics-mac-mini, against origin/main at 947d65e64, 80 min 22 s) | Check | Result | | --- | --- | | Scope | ✅ 4 files, +286 −48 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ➖ no Python change | | rustfmt | ✅ (6 s) | | clippy | ❌ failed (52 s) | | tests: horizon-assets, horizon-client | ✅ 1209 passed (5 min 15 s) | | doc tests | ✅ 0 passed (2 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ✅ 117 affected, 117 passed (72 min 48 s) | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | After rebasing onto 4a675206b: **pr_ready** (`tools/pr_ready.py --quick` on ludovics-mac-mini, against origin/main at 4a675206b, 8 min 49 s) | Check | Result | | --- | --- | | Scope | ✅ 4 files, +286 −48 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ (1 s) | | Python tests | ➖ no Python change | | rustfmt | ✅ (7 s) | | clippy | ✅ (28 s) | | tests: horizon-assets, horizon-client | ✅ 1210 passed (7 min 56 s) | | doc tests | ✅ 0 passed (4 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 114 affected, to run in CI (--quick): ambient_sound, arrow, audio_attributes, auto_jump, block_entity_anim, block_entity_render, block_entity_tickers, block_particles, block_removal, block_transformer, blockstate_binding, blockstate_model and 102 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | ## Needs Ludovic Nothing. No label: a speed-up players don't see as a feature. 🤖 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 04:11:54 +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#3739
No description provided.