[PR #5847] [MERGED] Start-up: block facts validate their JSON beside the decode (−186 ms) #6521

Closed
opened 2026-11-03 06:22:17 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: perf/startup-sp2


📝 Commits (1)

  • bef4061 Block facts: validate the JSON beside the decode

📊 Changes

5 files changed (+64 additions, -9 deletions)

View changed files

📝 crates/horizon-client/examples/shared_json_startup_profile.rs (+2 -1)
📝 crates/horizon-client/src/game.rs (+1 -1)
📝 crates/horizon-client/src/mod_content_tests.rs (+2 -2)
📝 crates/horizon-items/src/blocks.rs (+30 -5)
📝 crates/horizon-items/src/blocks/decode_tests.rs (+29 -0)

📄 Description

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

What

The block facts load parses gameplay-facts.json (56 MB) twice: a validation pass (decode::Validate) that only exists to keep the old loader's JSON errors, then the typed decode. The validation pass took 200-206 ms of the start's critical path on a 4-CPU host, with the other cores mostly idle at that point.

It now runs on a scoped thread while this thread decodes the file and builds the states; it is joined before the load returns, so a file it rejects still fails with its error first, as before. When the settings allow a single worker (parallel false, the same switch the other core-table loads use), the two passes run one after the other as they did.

Where the start goes (dedicated server, 4 CPUs, before this PR)

Timestamps from a bench build (stage logs), playhorizon, --cpus 0-3 --exclusive, new world:

Stage Wall CPU busy
core tables (registry, block facts, light, motion, collisions) 0 → 720 ms 1.3 cores
rest of the resources (items, behaviours, mobs…) 750 → 1,110 ms 2.0-2.5
worldgen data 1,110 → 1,480 ms 1.9
world prepare (generator, decoration, loot) 1,480 → 1,830 ms 1.0
spawn chunks 1,860 → 2,090 ms 2.0

Inside the core tables, the block facts are the long chain: gameplay facts read 12 ms, validation 200 ms, decode 172 ms, per-state loop 57 ms.

Measured

Same host, 6 alternated starts each, fresh world and data folders per start, idle RSS 32 s after Done:

main 7e5e3d1ad this PR
Done (median) 2.067 s 1.881 s (−186 ms, 6/6 faster)
load core tables (median) 0.70 s 0.52 s
idle RSS (median) 287 MB 294 MB (same: the spread is 285-316 on both)

Tests

  • New the_validation_error_still_fails_the_load_first: a file the typed decode reads but the validation pass rejects (a number out of range in a shape), with a behaviour document that would fail the load next, fails with the validation pass's JSON error in both modes. Checked that it fails if the decode's result is returned before the join.
  • cargo fmt --check, cargo clippy -p horizon-items -p horizon-client --lib --bins --tests --examples -- -D warnings: clean.

pr_ready (tools/pr_ready.py --quick on playhorizon, against origin/main at 7e5e3d1ad, 22 min 2 s)

Check Result
Scope ✅ 5 files, +64 −9
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ❌ 511 run, FAILED (failures=2, skipped=1) (46 s)
rustfmt ❌ failed
clippy ❌ failed
tests: horizon-client, horizon-items ✅ 1702 passed (14 min 40 s)
doc tests ✅ 0 passed (2 s)
content root tests ✅ 20 passed (6 min 21 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 122 affected, to run in CI (--quick): ambient_sound, arrow, audio_attributes, auto_jump, blending, block_entity_anim, block_entity_render, block_entity_tickers, block_particles, block_removal, block_tint, block_transformer and 110 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

Notes: playhorizon's toolchain has no rustfmt/clippy, so both ran on the Mac (cargo fmt --check clean, cargo clippy -p horizon-items -p horizon-client --lib --bins --tests --examples -- -D warnings clean). The two Python failures are that host's virtual-screen tests; on the Mac python3 -m unittest discover -s tests runs 511, OK.

🤖 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/5847 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/startup-sp2` --- ### 📝 Commits (1) - [`bef4061`](https://github.com/horizon-rust/horizon/commit/bef40610526c241ba6fd4dc50d756143e8d8b56a) Block facts: validate the JSON beside the decode ### 📊 Changes **5 files changed** (+64 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/examples/shared_json_startup_profile.rs` (+2 -1) 📝 `crates/horizon-client/src/game.rs` (+1 -1) 📝 `crates/horizon-client/src/mod_content_tests.rs` (+2 -2) 📝 `crates/horizon-items/src/blocks.rs` (+30 -5) 📝 `crates/horizon-items/src/blocks/decode_tests.rs` (+29 -0) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What The block facts load parses `gameplay-facts.json` (56 MB) twice: a validation pass (`decode::Validate`) that only exists to keep the old loader's JSON errors, then the typed decode. The validation pass took 200-206 ms of the start's critical path on a 4-CPU host, with the other cores mostly idle at that point. It now runs on a scoped thread while this thread decodes the file and builds the states; it is joined before the load returns, so a file it rejects still fails with its error first, as before. When the settings allow a single worker (`parallel` false, the same switch the other core-table loads use), the two passes run one after the other as they did. ## Where the start goes (dedicated server, 4 CPUs, before this PR) Timestamps from a bench build (stage logs), playhorizon, `--cpus 0-3 --exclusive`, new world: | Stage | Wall | CPU busy | |---|---|---| | core tables (registry, block facts, light, motion, collisions) | 0 → 720 ms | 1.3 cores | | rest of the resources (items, behaviours, mobs…) | 750 → 1,110 ms | 2.0-2.5 | | worldgen data | 1,110 → 1,480 ms | 1.9 | | world prepare (generator, decoration, loot) | 1,480 → 1,830 ms | 1.0 | | spawn chunks | 1,860 → 2,090 ms | 2.0 | Inside the core tables, the block facts are the long chain: gameplay facts read 12 ms, **validation 200 ms**, decode 172 ms, per-state loop 57 ms. ## Measured Same host, 6 alternated starts each, fresh world and data folders per start, idle RSS 32 s after Done: | | main 7e5e3d1ad | this PR | |---|---|---| | Done (median) | 2.067 s | **1.881 s** (−186 ms, 6/6 faster) | | `load core tables` (median) | 0.70 s | **0.52 s** | | idle RSS (median) | 287 MB | 294 MB (same: the spread is 285-316 on both) | ## Tests - New `the_validation_error_still_fails_the_load_first`: a file the typed decode reads but the validation pass rejects (a number out of range in a shape), with a behaviour document that would fail the load next, fails with the validation pass's JSON error in both modes. Checked that it fails if the decode's result is returned before the join. - `cargo fmt --check`, `cargo clippy -p horizon-items -p horizon-client --lib --bins --tests --examples -- -D warnings`: clean. **pr_ready** (`tools/pr_ready.py --quick` on playhorizon, against origin/main at 7e5e3d1ad, 22 min 2 s) | Check | Result | | --- | --- | | Scope | ✅ 5 files, +64 −9 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ❌ 511 run, FAILED (failures=2, skipped=1) (46 s) | | rustfmt | ❌ failed | | clippy | ❌ failed | | tests: horizon-client, horizon-items | ✅ 1702 passed (14 min 40 s) | | doc tests | ✅ 0 passed (2 s) | | content root tests | ✅ 20 passed (6 min 21 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 122 affected, to run in CI (--quick): ambient_sound, arrow, audio_attributes, auto_jump, blending, block_entity_anim, block_entity_render, block_entity_tickers, block_particles, block_removal, block_tint, block_transformer and 110 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | Notes: playhorizon's toolchain has no rustfmt/clippy, so both ran on the Mac (`cargo fmt --check` clean, `cargo clippy -p horizon-items -p horizon-client --lib --bins --tests --examples -- -D warnings` clean). The two Python failures are that host's virtual-screen tests; on the Mac `python3 -m unittest discover -s tests` runs 511, OK. 🤖 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 06:22: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#6521
No description provided.