[PR #2006] [MERGED] Behaviour cache: hash the source files once per process #3933

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

📋 Pull Request Information

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

Base: main ← Head: perf/behaviour-cache-hash-once


📝 Commits (3)

  • 2fb0ac1 Behaviour cache: hash the source files once per process
  • da66056 Merge remote-tracking branch 'origin/main' into perf/behaviour-cache-hash-once
  • 4457d4e Merge remote-tracking branch 'origin/main' into perf/behaviour-cache-hash-once

📊 Changes

1 file changed (+78 additions, -18 deletions)

View changed files

📝 crates/horizon-world/src/level/data/cache.rs (+78 -18)

📄 Description

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

The block-behaviour cache's fingerprint now hashes its source files (about 70 MB of facts.json, block-behaviours.json, gameplay-facts.json, block-tags.json, cached-collision.nbt and the fluid tags) once per process, instead of each time a table is loaded from the same folder.

When single player opens a world, the window loads the behaviour tables, and so does the server thread's world generator (GeneratorData::load's own Behaviours::load). Each computed the same SHA-256 over the same files: about 0.38 s of CPU each on a 4-thread laptop, on the path before the first chunk. The digest is now kept per folder, keyed by every file's path, length and modification time. A file that changes length or modification time is read and hashed again, and the cache is then rebuilt as before. The fingerprint's other inputs (the registry, the binary's own stamp) are unchanged.

Measured

ThinkPad (i5-7200U, 4 threads), fresh world entry with --offscreen --creative, perf record -F 999 over the whole run (about 113 K samples per run), two runs each:

sha2::sha256::compress256, share of all samples before this branch
run 1 1.54% 0.93%
run 2 2.29% 0.91%

Time to the first chunk did not move beyond the noise: 10.6 / 11.8 / 11.8 s before, 11.2 / 11.3 / 11.6 s here. Another session's build kept the 1-minute load at 5–7 during those runs. This is CPU saved on the startup path, not a visible change by itself.

A new test (sources_are_hashed_once_until_a_file_changes) checks that a folder is hashed once and that a file rewritten at the same length, which changes its modification time, is hashed again.

Self-check

pr_ready (tools/pr_ready.py on Ludovics-Mac-mini, against origin/main at b3149d43e, 99 min 28 s)

Check Result
Scope ✅ 11 files, +361 −48
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ❌ 299 run, FAILED (errors=2) (1 min 52 s)
rustfmt ✅ (13 s)
clippy ✅ (1 min 18 s)
tests: horizon-client, horizon-threads, horizon-world ✅ 1500 passed (11 min 47 s)
doc tests ✅ 0 passed (9 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ✅ 91 affected, 91 passed (82 min 34 s)

One run for three branches: a merge of perf/sculk-ticking-chunks, perf/rings-out-of-reach (at 8b26c4cf3), perf/behaviour-cache-hash-once and #1991 (pr_ready's selection fix, without which pr_ready did not get past its plan). The 2 Python errors are main's on macOS (OracleReuseTests exit 127, a /private/var path in ParityRunnerTests); none of these branches touch Python.

🤖 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/2006 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/26/2026 **Status:** ✅ Merged **Merged:** 10/26/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/behaviour-cache-hash-once` --- ### 📝 Commits (3) - [`2fb0ac1`](https://github.com/horizon-rust/horizon/commit/2fb0ac186a65b1171d0893c409e040dd094a95b6) Behaviour cache: hash the source files once per process - [`da66056`](https://github.com/horizon-rust/horizon/commit/da66056bd51131e7e05e00f045dcd40ca278437d) Merge remote-tracking branch 'origin/main' into perf/behaviour-cache-hash-once - [`4457d4e`](https://github.com/horizon-rust/horizon/commit/4457d4e0ca171923ff4ce52f158f7b9de04dfa96) Merge remote-tracking branch 'origin/main' into perf/behaviour-cache-hash-once ### 📊 Changes **1 file changed** (+78 additions, -18 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-world/src/level/data/cache.rs` (+78 -18) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. The block-behaviour cache's fingerprint now hashes its source files (about 70 MB of `facts.json`, `block-behaviours.json`, `gameplay-facts.json`, `block-tags.json`, `cached-collision.nbt` and the fluid tags) once per process, instead of each time a table is loaded from the same folder. When single player opens a world, the window loads the behaviour tables, and so does the server thread's world generator (`GeneratorData::load`'s own `Behaviours::load`). Each computed the same SHA-256 over the same files: about 0.38 s of CPU each on a 4-thread laptop, on the path before the first chunk. The digest is now kept per folder, keyed by every file's path, length and modification time. A file that changes length or modification time is read and hashed again, and the cache is then rebuilt as before. The fingerprint's other inputs (the registry, the binary's own stamp) are unchanged. ## Measured ThinkPad (i5-7200U, 4 threads), fresh world entry with `--offscreen --creative`, `perf record -F 999` over the whole run (about 113 K samples per run), two runs each: | `sha2::sha256::compress256`, share of all samples | before | this branch | |---|---|---| | run 1 | 1.54% | 0.93% | | run 2 | 2.29% | 0.91% | Time to the first chunk did not move beyond the noise: 10.6 / 11.8 / 11.8 s before, 11.2 / 11.3 / 11.6 s here. Another session's build kept the 1-minute load at 5–7 during those runs. This is CPU saved on the startup path, not a visible change by itself. A new test (`sources_are_hashed_once_until_a_file_changes`) checks that a folder is hashed once and that a file rewritten at the same length, which changes its modification time, is hashed again. ## Self-check **pr_ready** (`tools/pr_ready.py` on Ludovics-Mac-mini, against origin/main at b3149d43e, 99 min 28 s) | Check | Result | | --- | --- | | Scope | ✅ 11 files, +361 −48 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ❌ 299 run, FAILED (errors=2) (1 min 52 s) | | rustfmt | ✅ (13 s) | | clippy | ✅ (1 min 18 s) | | tests: horizon-client, horizon-threads, horizon-world | ✅ 1500 passed (11 min 47 s) | | doc tests | ✅ 0 passed (9 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ✅ 91 affected, 91 passed (82 min 34 s) | One run for three branches: a merge of `perf/sculk-ticking-chunks`, `perf/rings-out-of-reach` (at 8b26c4cf3), `perf/behaviour-cache-hash-once` and #1991 (pr_ready's selection fix, without which pr_ready did not get past its plan). The 2 Python errors are main's on macOS (`OracleReuseTests` exit 127, a `/private/var` path in `ParityRunnerTests`); none of these branches touch Python. 🤖 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:13:21 +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#3933
No description provided.