[PR #607] [MERGED] perf: reuse decoded gameplay and behaviour facts at startup #2673

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

📋 Pull Request Information

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

Base: main ← Head: perf/shared-block-json-20261017


📝 Commits (8)

  • a01d47f perf: share decoded block facts during client startup
  • cf83711 perf: defer behaviour construction and test fresh resource loads
  • cd61e11 perf: intern gameplay projection strings and verify resource overrides
  • 73ac737 perf: release startup decode buffers and profile parsing tradeoffs
  • 7b7c4eb Merge remote-tracking branch 'origin/main' into perf/shared-block-json-20261017
  • ef633b2 test: run parity from worktrees and document startup profiles
  • 2a593ea Merge remote-tracking branch 'origin/main' into perf/shared-block-json-20261017
  • 5725ee0 Give the shared-JSON profiler its own name

📊 Changes

22 files changed (+3570 additions, -58 deletions)

View changed files

➕ benchmarks/shared-json-buffer-lifetime-20261017.json (+379 -0)
➕ benchmarks/shared-json-decoder-phases-20261017.json (+176 -0)
➕ benchmarks/shared-json-five-way-20261017.json (+453 -0)
➕ benchmarks/shared-json-five-way-final-20261017.json (+582 -0)
➕ benchmarks/shared-json-historical-20261017.json (+188 -0)
➕ benchmarks/shared-json-startup-20261017.json (+93 -0)
➕ benchmarks/shared-json-startup-followup-20261017.json (+227 -0)
➕ benchmarks/shared-json-variant-isolation-20261017.json (+453 -0)
➕ crates/horizon-client/examples/gameplay_decode_profile.rs (+33 -0)
➕ crates/horizon-client/examples/shared_json_startup_profile.rs (+74 -0)
📝 crates/horizon-client/src/blocks.rs (+236 -13)
📝 crates/horizon-client/src/blocks/decode.rs (+6 -3)
📝 crates/horizon-client/src/blocks/decode_tests.rs (+3 -3)
📝 crates/horizon-client/src/game.rs (+15 -2)
📝 crates/horizon-client/src/mod_content_tests.rs (+228 -2)
📝 crates/horizon-client/src/random_tick_sections.rs (+10 -4)
📝 crates/horizon-world/src/level/data.rs (+62 -31)
📝 crates/horizon-world/src/level/mod.rs (+28 -0)
➕ tools/PROFILE_SHARED_JSON.md (+85 -0)
➕ tools/baseline_loader_profile.rs (+23 -0)

...and 2 more files

📄 Description

Problem and resulting behavior

The client originally read and parsed block-behaviours.json independently in BlockFacts::load and Behaviours::load, and both paths decoded gameplay-facts.json. Startup now shares the behaviour document and the decoded gameplay projection while preserving resource-pack/mod root selection. The client still constructs Behaviours at the original initialization stage.

The latest integration pass also explicitly drops the temporary behaviour JSON and owned gameplay projection once Resources has been constructed, so those Rust objects do not persist through the long-running client loop. The allocator may retain their freed pages: we measured no meaningful immediate resident-RSS reduction from this drop, so no post-startup memory gain is claimed.

Standalone BlockFacts::load and Behaviours::load remain public, independent and fresh per call. load_pair is available for callers requiring both; the random-tick parity caller uses it. No process-wide cache, filesystem timestamp key, stale snapshot, or implicit cross-root sharing is introduced. load_with_projection owns only fields needed by Behaviours, with the already established conservative JSON numeric and error semantics.

Audit and design decisions

  • Reviewed all production, tests, fixture and example callers. Most remaining independent calls need only one table; forcing pair construction would waste work. The worldgen and world-level paths remain independently loadable.
  • Tested alternatives to the cd61e11b projection: Arc-keyed string pools, borrowing sound IDs from existing state facts, and direct flag bit packing. Interleaved release profiles showed overlapping CPU/latency distributions and slightly higher or unchanged peak RSS; these alternatives were reverted. Raw experimental samples are retained in benchmarks/shared-json-variant-isolation-20261017.json and benchmarks/shared-json-five-way-20261017.json for review, explicitly marked as rejected experiments.
  • The gameplay-facts.json decoder still runs a validation pass before the typed pass. Its purpose is precise JSON diagnostics, error precedence, depth and number errors even in skipped/overwritten/raw fields. A one-pass replacement was not adopted without evidence it preserves those semantics. No speculative global cache or intrusive deserializer changes were added.
  • The worktree-safe random-tick fixture now actually executes parity rather than silently skipping when the default relative prepared-resource path is absent.
  • Merged newer origin/main changes into this existing branch without rewriting a01d47f2, cf837118, or cd61e11b; upstream mining-screen and F3 packet-rate changes remain intact.

Reproducible release profiling

Full rebuild steps, historical profiler source, exact mode arguments, environment guidance and limitations: tools/PROFILE_SHARED_JSON.md. tools/profile_client_startup.py now accepts exact historical release executables and arbitrary interleaved candidate variants, records each executable's SHA-256, process CPU and Linux peak RSS, median, quartiles, minima/maxima, all raw samples, run order and load average. The pre-PR baseline uses the tracked tools/baseline_loader_profile.rs example without changing historical production code.

The final table comes from 10 alternating rounds on prepared Minecraft 26.3 resources. Values are medians with 25th–75th percentile intervals. CPU means user+system process CPU time; RSS is process peak, not heap size.

Release implementation Block-loading phase (ms) Total loader time incl. Assets (ms) Process CPU (ms) Peak RSS (KiB)
Original e422bd13 1,507 [1,388–2,120] 1,962 [1,858–3,153] 1,969 [1,893–2,695] 819,952 [819,778–820,164]
a01d47f2 667 [520–1,156] 1,142 [975–2,327] 1,107 [974–1,526] 351,564 [351,148–352,106]
cf837118 505 [435–1,104] 1,209 [896–2,133] 1,068 [897–1,489] 273,832 [273,592–274,131]
cd61e11b 429 [410–1,178] 903 [869–2,443] 921 [870–1,476] 267,762 [267,612–267,966]
Integrated branch 460 [429–987] 936 [874–2,283] 951 [893–1,541] 268,010 [267,013–268,385]

Interpretation: The shared-decoding path shows a large measured improvement against original independent loading. The integrated branch and cd61e11b use the same production loader algorithm; the few-percent median differences are not established new gains or regressions. System load increased from ~11.5 to ~17.8 during the final run, and early samples were markedly slower across all modes. Keep the raw data and distributions rather than treating one median as definitive. No CPU, memory, or full-startup gain is attributed to the latest lifetime fix.

Raw historical sample file: benchmarks/shared-json-five-way-final-20261017.json. Separate variants: benchmarks/shared-json-variant-isolation-20261017.json. The current benchmark example additionally reports behaviour_json_ms, facts_ms, and behaviours_ms to distinguish parse/decode/materialisation stages.

Decoder cost: Ten separate-process runs of tools/profile_gameplay_decode.py measured median validation ~117 ms and typed decode ~116 ms, with raw quartiles/CPU/RSS in benchmarks/shared-json-decoder-phases-20261017.json. This quantifies the remaining validation expense; it does not justify removing error checks.

Temporary buffer lifetime: Ten alternated same-executable runs of retained versus released input buffers had median post-construction RSS of 268,694 versus 268,668 KiB, respectively, an insignificant 26 KiB difference. This test is captured in benchmarks/shared-json-buffer-lifetime-20261017.json; allocator retention explains why immediate RSS cannot be inferred from object destruction.

Compatibility and regression evidence

  • Prepared-resource state parity: independent, paired and deferred loads agree for every registered state on class chains, behaviour flags, light/hardness, fluid state, push reaction, collision shape IDs, and sound values.
  • All 8 mod-content tests passed, including generated ruby block/door/glass overrides, independent/paired ordering, same-root file mutation, separate base-root freshness, malformed/incomplete behaviour and gameplay JSON, restoration, and matching independent/paired behaviour errors.
  • All 3 typed decoder tests passed, checking duplicate keys, wrong-type/default handling, malformed raw geometry, numeric semantics and shape identity.
  • 31 world-level tests passed, and the resource-backed random-tick parity test executed and passed after correcting worktree resource discovery.
  • Post-upstream-merge cargo fmt --all -- --check, cargo check --offline -q -p horizon-client -p horizon-world, standalone profiling-example checks and git diff --check passed.

The measured scope is Assets + block facts + behaviour tables in isolated release processes. It does not include resource-pack/mod preparation, the entire client startup, GPU/render setup, or first playable frame; reliable full-client startup instrumentation is not presently available. Runtime behavior when packs change still requires explicit new loading calls, and no parsed documents are cached across roots or invocations.


🔄 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/607 **Author:** [@rdbtCVS](https://github.com/rdbtCVS) **Created:** 10/17/2026 **Status:** ✅ Merged **Merged:** 10/17/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/shared-block-json-20261017` --- ### 📝 Commits (8) - [`a01d47f`](https://github.com/horizon-rust/horizon/commit/a01d47f28fc9ce3868d6954b46d0d1b3ed9be8a1) perf: share decoded block facts during client startup - [`cf83711`](https://github.com/horizon-rust/horizon/commit/cf837118e98eae9b96e664d418c16bcc36091187) perf: defer behaviour construction and test fresh resource loads - [`cd61e11`](https://github.com/horizon-rust/horizon/commit/cd61e11b566637372e2f259eebf12f486626e10e) perf: intern gameplay projection strings and verify resource overrides - [`73ac737`](https://github.com/horizon-rust/horizon/commit/73ac737ccf59453c1ce569cfdadea6aa890603e4) perf: release startup decode buffers and profile parsing tradeoffs - [`7b7c4eb`](https://github.com/horizon-rust/horizon/commit/7b7c4eb083f8a5817bc17ddaa231813ae0ad902f) Merge remote-tracking branch 'origin/main' into perf/shared-block-json-20261017 - [`ef633b2`](https://github.com/horizon-rust/horizon/commit/ef633b252f61a1562b7355554ae015ee1ffd635a) test: run parity from worktrees and document startup profiles - [`2a593ea`](https://github.com/horizon-rust/horizon/commit/2a593ea64fee15bd79c24f608bf547e877cb24f6) Merge remote-tracking branch 'origin/main' into perf/shared-block-json-20261017 - [`5725ee0`](https://github.com/horizon-rust/horizon/commit/5725ee0efab6436e4d051bdf05fda5e7d3054399) Give the shared-JSON profiler its own name ### 📊 Changes **22 files changed** (+3570 additions, -58 deletions) <details> <summary>View changed files</summary> ➕ `benchmarks/shared-json-buffer-lifetime-20261017.json` (+379 -0) ➕ `benchmarks/shared-json-decoder-phases-20261017.json` (+176 -0) ➕ `benchmarks/shared-json-five-way-20261017.json` (+453 -0) ➕ `benchmarks/shared-json-five-way-final-20261017.json` (+582 -0) ➕ `benchmarks/shared-json-historical-20261017.json` (+188 -0) ➕ `benchmarks/shared-json-startup-20261017.json` (+93 -0) ➕ `benchmarks/shared-json-startup-followup-20261017.json` (+227 -0) ➕ `benchmarks/shared-json-variant-isolation-20261017.json` (+453 -0) ➕ `crates/horizon-client/examples/gameplay_decode_profile.rs` (+33 -0) ➕ `crates/horizon-client/examples/shared_json_startup_profile.rs` (+74 -0) 📝 `crates/horizon-client/src/blocks.rs` (+236 -13) 📝 `crates/horizon-client/src/blocks/decode.rs` (+6 -3) 📝 `crates/horizon-client/src/blocks/decode_tests.rs` (+3 -3) 📝 `crates/horizon-client/src/game.rs` (+15 -2) 📝 `crates/horizon-client/src/mod_content_tests.rs` (+228 -2) 📝 `crates/horizon-client/src/random_tick_sections.rs` (+10 -4) 📝 `crates/horizon-world/src/level/data.rs` (+62 -31) 📝 `crates/horizon-world/src/level/mod.rs` (+28 -0) ➕ `tools/PROFILE_SHARED_JSON.md` (+85 -0) ➕ `tools/baseline_loader_profile.rs` (+23 -0) _...and 2 more files_ </details> ### 📄 Description ## Problem and resulting behavior The client originally read and parsed `block-behaviours.json` independently in `BlockFacts::load` and `Behaviours::load`, and both paths decoded `gameplay-facts.json`. Startup now shares the behaviour document and the decoded gameplay projection while preserving resource-pack/mod root selection. The client still constructs `Behaviours` at the original initialization stage. The latest integration pass also explicitly drops the temporary behaviour JSON and owned gameplay projection once `Resources` has been constructed, so those Rust objects do not persist through the long-running client loop. The allocator may retain their freed pages: **we measured no meaningful immediate resident-RSS reduction** from this drop, so no post-startup memory gain is claimed. Standalone `BlockFacts::load` and `Behaviours::load` remain public, independent and fresh per call. `load_pair` is available for callers requiring both; the random-tick parity caller uses it. No process-wide cache, filesystem timestamp key, stale snapshot, or implicit cross-root sharing is introduced. `load_with_projection` owns only fields needed by `Behaviours`, with the already established conservative JSON numeric and error semantics. ## Audit and design decisions - Reviewed all production, tests, fixture and example callers. Most remaining independent calls need only one table; forcing pair construction would waste work. The worldgen and world-level paths remain independently loadable. - Tested alternatives to the `cd61e11b` projection: Arc-keyed string pools, borrowing sound IDs from existing state facts, and direct flag bit packing. Interleaved release profiles showed overlapping CPU/latency distributions and slightly higher or unchanged peak RSS; **these alternatives were reverted**. Raw experimental samples are retained in `benchmarks/shared-json-variant-isolation-20261017.json` and `benchmarks/shared-json-five-way-20261017.json` for review, explicitly marked as rejected experiments. - The `gameplay-facts.json` decoder still runs a validation pass before the typed pass. Its purpose is precise JSON diagnostics, error precedence, depth and number errors even in skipped/overwritten/raw fields. A one-pass replacement was not adopted without evidence it preserves those semantics. No speculative global cache or intrusive deserializer changes were added. - The worktree-safe random-tick fixture now actually executes parity rather than silently skipping when the default relative prepared-resource path is absent. - Merged newer `origin/main` changes into this existing branch without rewriting `a01d47f2`, `cf837118`, or `cd61e11b`; upstream mining-screen and F3 packet-rate changes remain intact. ## Reproducible release profiling Full rebuild steps, historical profiler source, exact mode arguments, environment guidance and limitations: **`tools/PROFILE_SHARED_JSON.md`**. `tools/profile_client_startup.py` now accepts exact historical release executables and arbitrary interleaved candidate variants, records each executable's SHA-256, process CPU and Linux peak RSS, median, quartiles, minima/maxima, all raw samples, run order and load average. The pre-PR baseline uses the tracked `tools/baseline_loader_profile.rs` example without changing historical production code. The final table comes from **10 alternating rounds** on prepared Minecraft 26.3 resources. Values are medians with 25th–75th percentile intervals. CPU means user+system process CPU time; RSS is process peak, not heap size. | Release implementation | Block-loading phase (ms) | Total loader time incl. Assets (ms) | Process CPU (ms) | Peak RSS (KiB) | | --- | ---: | ---: | ---: | ---: | | Original `e422bd13` | 1,507 [1,388–2,120] | 1,962 [1,858–3,153] | 1,969 [1,893–2,695] | 819,952 [819,778–820,164] | | `a01d47f2` | 667 [520–1,156] | 1,142 [975–2,327] | 1,107 [974–1,526] | 351,564 [351,148–352,106] | | `cf837118` | 505 [435–1,104] | 1,209 [896–2,133] | 1,068 [897–1,489] | 273,832 [273,592–274,131] | | `cd61e11b` | 429 [410–1,178] | 903 [869–2,443] | 921 [870–1,476] | 267,762 [267,612–267,966] | | Integrated branch | 460 [429–987] | 936 [874–2,283] | 951 [893–1,541] | 268,010 [267,013–268,385] | **Interpretation:** The shared-decoding path shows a large measured improvement against original independent loading. The integrated branch and `cd61e11b` use the same production loader algorithm; the few-percent median differences are not established new gains or regressions. System load increased from ~11.5 to ~17.8 during the final run, and early samples were markedly slower across all modes. Keep the raw data and distributions rather than treating one median as definitive. No CPU, memory, or full-startup gain is attributed to the latest lifetime fix. Raw historical sample file: `benchmarks/shared-json-five-way-final-20261017.json`. Separate variants: `benchmarks/shared-json-variant-isolation-20261017.json`. The current benchmark example additionally reports `behaviour_json_ms`, `facts_ms`, and `behaviours_ms` to distinguish parse/decode/materialisation stages. **Decoder cost:** Ten separate-process runs of `tools/profile_gameplay_decode.py` measured median validation ~117 ms and typed decode ~116 ms, with raw quartiles/CPU/RSS in `benchmarks/shared-json-decoder-phases-20261017.json`. This quantifies the remaining validation expense; it does not justify removing error checks. **Temporary buffer lifetime:** Ten alternated same-executable runs of retained versus released input buffers had median post-construction RSS of 268,694 versus 268,668 KiB, respectively, an insignificant 26 KiB difference. This test is captured in `benchmarks/shared-json-buffer-lifetime-20261017.json`; allocator retention explains why immediate RSS cannot be inferred from object destruction. ## Compatibility and regression evidence - Prepared-resource state parity: independent, paired and deferred loads agree for every registered state on class chains, behaviour flags, light/hardness, fluid state, push reaction, collision shape IDs, and sound values. - All **8 mod-content tests** passed, including generated ruby block/door/glass overrides, independent/paired ordering, same-root file mutation, separate base-root freshness, malformed/incomplete behaviour and gameplay JSON, restoration, and matching independent/paired behaviour errors. - All **3 typed decoder tests** passed, checking duplicate keys, wrong-type/default handling, malformed raw geometry, numeric semantics and shape identity. - **31 world-level tests** passed, and the resource-backed random-tick parity test **executed and passed** after correcting worktree resource discovery. - Post-upstream-merge `cargo fmt --all -- --check`, `cargo check --offline -q -p horizon-client -p horizon-world`, standalone profiling-example checks and `git diff --check` passed. The measured scope is `Assets` + block facts + behaviour tables in isolated release processes. It **does not** include resource-pack/mod preparation, the entire client startup, GPU/render setup, or first playable frame; reliable full-client startup instrumentation is not presently available. Runtime behavior when packs change still requires explicit new loading calls, and no parsed documents are cached across roots or invocations. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 15:58:07 +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#2673
No description provided.