[PR #943] [MERGED] Cache carver biome lookups per generator worker #2929

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

📋 Pull Request Information

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

Base: main ← Head: t3/reduce-carver-cache-locks


📝 Commits (1)

  • 745c756 perf(worldgen): cache carver biomes per worker

📊 Changes

1 file changed (+66 additions, -2 deletions)

View changed files

📝 crates/horizon-world/src/worldgen/generator.rs (+66 -2)

📄 Description

Terrain generation repeatedly samples the same carver origins across overlapping 17×17 neighborhoods. Each lookup currently acquires the shared carver biome cache mutex. Keep up to 4,096 resolved origins per generator worker so repeat lookups avoid that mutex; local misses use the existing shared cache and original biome resolver. Workers remain bound to one seed and dimension, and local eviction only drops memoized values.

Acceptance gate: at least 2% median paired terrain throughput improvement at both declared six-worker Overworld sites, with no >2% single-worker regression. Both sites pass after 16 measured alternating pairs each; five-pair size-32 confirmation also passes. Baseline is f422cbb79ae96d3a12e9289e84d1150bac21a293; candidate changes only the carver lookup cache and its correctness test.

Workload, six workers Primary terrain gain Secondary terrain gain Primary combined gain Secondary combined gain
Size 16, 16 pairs 3.28% 3.91% 3.35% 3.47%
Size 32, 5 pairs 3.99% 5.90% 3.37% 4.98%

Primary: seed 12345, center (0,0). Secondary: seed -1, center (32,-32). Size 16 means 256 terrain chunks and 196 decorated interiors; size 32 means 1,024 terrain chunks and 900 decorated interiors. Combined throughput uses the complete terrain plus decoration time for the same input count.

Scaling (three measured pairs per case, rotated worker order):

Workers Primary terrain gain Secondary terrain gain Primary combined gain Secondary combined gain
1 4.87% 4.01% 4.22% 3.83%
2 4.30% 3.32% 4.21% 3.31%
4 2.00% 4.72% 1.78% 4.07%
6 2.81% 2.56% 3.34% 2.36%
8 1.21% 1.76% 1.25% 1.71%

Machine: Ryzen 5 5600X, 32 GiB RAM, Linux 7.2.11-zen1, Rust 1.99.0. Both builds use the same fast profile (release optimization, LTO off, 16 codegen units), resources and temporary instrumentation based on the existing chunkgen_bench. Every run warms the seeded generator through a discarded offset 9×9 terrain region, with fresh measured workers; cold startup and warmup are recorded separately. Timings are exact elapsed/count, and each round discards its initial alternating pair. All measured runs and builds are sequential; all paired ratios are retained. Primary was near the threshold after eight pairs, so eight further pairs were added at both sites before deciding.

CPU time per input chunk also improves in the 16-pair corpus. Carver stage medians are essentially unchanged, so these data do not establish reduced mutex contention as the cause of the overall throughput gain. Eight-worker gains are below 2%; this is a result for the declared workloads and machine, with desktop noise, rather than an architectural or universal performance guarantee.

Validation:

  • Eight complete byte-exact baseline/candidate comparisons: terrain and decorated output at both sites, size 16, with 1/6 workers. These cover all chunks, section palettes/block states, quart biomes, entity/block-entity NBT, heightmaps, ordered postprocessing, scheduled ticks, non-air counts and metadata. One-/six-worker snapshots also match each other.
  • Targeted worker ownership and forced-eviction test passes with resources explicitly enabled; full horizon-world suite: 187 passed.
  • Fresh pinned client and server parity: cave (415 fixtures, 882,005 matching lines/side), canyon (508 fixtures, 1,094,517 lines/side), carving mask (28 fixtures, 45,742 lines/side).
  • Final source rebuild is byte-identical to the measured candidate executable (SHA256 1a7acdbb6af7e047c4adff6ef02176a4e24c330c380859bdf6ec4aaf9d1cf830).
  • python3 tools/pr_ready.py --base origin/main --quick passes public-tree checks, formatting, workspace clippy and world tests. Python checks were skipped because Python is unchanged. The quick check omits the broader 307 affected parity suites; the three explicit fresh suites and complete differential corpus above cover this change's declared validation scope, not universal vanilla parity.

Reproduction tooling and raw evidence are retained outside git at /tmp/horizon-concurrency-20261018/{shared,carver}. shared/prepare_runner.py CHECKOUT installs the same optional offset initialization, exact JSON timings and complete snapshot instrumentation on either revision. Build sequentially with:

CARGO_TARGET_DIR=/srv/bob-data/horizon-concurrency-target cargo build --profile fast -p horizon-world --example concurrency_bench
python3 /tmp/horizon-concurrency-20261018/shared/compare_outputs.py --baseline BASELINE --candidate CANDIDATE --out OUTPUT
python3 /tmp/horizon-concurrency-20261018/shared/run_pairs.py --baseline BASELINE --candidate CANDIDATE --out OUTPUT --phase gate
# Repeat into another output directory for the additional eight pairs.
# Other phases: screen (3 pairs), scaling (3 pairs/count), large (5 pairs).

Resources: /srv/bob-data/horizon/.local/horizon-client/26.3. The preserved baseline executable is shared/baseline-f422cbb7; commands.sh, raw JSON, exact snapshot files/hashes, individual logs, executable hashes, and the complete local report are in carver/. Diagnostics and generated artifacts are excluded from the PR.


🔄 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/943 **Author:** [@rdbtCVS](https://github.com/rdbtCVS) **Created:** 10/18/2026 **Status:** ✅ Merged **Merged:** 10/18/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `t3/reduce-carver-cache-locks` --- ### 📝 Commits (1) - [`745c756`](https://github.com/horizon-rust/horizon/commit/745c756df52db1be9dc8ba0d601dc0a211fd5f12) perf(worldgen): cache carver biomes per worker ### 📊 Changes **1 file changed** (+66 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-world/src/worldgen/generator.rs` (+66 -2) </details> ### 📄 Description Terrain generation repeatedly samples the same carver origins across overlapping 17×17 neighborhoods. Each lookup currently acquires the shared carver biome cache mutex. Keep up to 4,096 resolved origins per generator worker so repeat lookups avoid that mutex; local misses use the existing shared cache and original biome resolver. Workers remain bound to one seed and dimension, and local eviction only drops memoized values. Acceptance gate: at least 2% median paired terrain throughput improvement at both declared six-worker Overworld sites, with no >2% single-worker regression. Both sites pass after 16 measured alternating pairs each; five-pair size-32 confirmation also passes. Baseline is `f422cbb79ae96d3a12e9289e84d1150bac21a293`; candidate changes only the carver lookup cache and its correctness test. | Workload, six workers | Primary terrain gain | Secondary terrain gain | Primary combined gain | Secondary combined gain | | --- | ---: | ---: | ---: | ---: | | Size 16, 16 pairs | 3.28% | 3.91% | 3.35% | 3.47% | | Size 32, 5 pairs | 3.99% | 5.90% | 3.37% | 4.98% | Primary: seed 12345, center (0,0). Secondary: seed -1, center (32,-32). Size 16 means 256 terrain chunks and 196 decorated interiors; size 32 means 1,024 terrain chunks and 900 decorated interiors. Combined throughput uses the complete terrain plus decoration time for the same input count. Scaling (three measured pairs per case, rotated worker order): | Workers | Primary terrain gain | Secondary terrain gain | Primary combined gain | Secondary combined gain | | --- | ---: | ---: | ---: | ---: | | 1 | 4.87% | 4.01% | 4.22% | 3.83% | | 2 | 4.30% | 3.32% | 4.21% | 3.31% | | 4 | 2.00% | 4.72% | 1.78% | 4.07% | | 6 | 2.81% | 2.56% | 3.34% | 2.36% | | 8 | 1.21% | 1.76% | 1.25% | 1.71% | Machine: Ryzen 5 5600X, 32 GiB RAM, Linux 7.2.11-zen1, Rust 1.99.0. Both builds use the same `fast` profile (release optimization, LTO off, 16 codegen units), resources and temporary instrumentation based on the existing `chunkgen_bench`. Every run warms the seeded generator through a discarded offset 9×9 terrain region, with fresh measured workers; cold startup and warmup are recorded separately. Timings are exact elapsed/count, and each round discards its initial alternating pair. All measured runs and builds are sequential; all paired ratios are retained. Primary was near the threshold after eight pairs, so eight further pairs were added at both sites before deciding. CPU time per input chunk also improves in the 16-pair corpus. Carver stage medians are essentially unchanged, so these data do not establish reduced mutex contention as the cause of the overall throughput gain. Eight-worker gains are below 2%; this is a result for the declared workloads and machine, with desktop noise, rather than an architectural or universal performance guarantee. Validation: - Eight complete byte-exact baseline/candidate comparisons: terrain and decorated output at both sites, size 16, with 1/6 workers. These cover all chunks, section palettes/block states, quart biomes, entity/block-entity NBT, heightmaps, ordered postprocessing, scheduled ticks, non-air counts and metadata. One-/six-worker snapshots also match each other. - Targeted worker ownership and forced-eviction test passes with resources explicitly enabled; full `horizon-world` suite: 187 passed. - Fresh pinned client **and** server parity: cave (415 fixtures, 882,005 matching lines/side), canyon (508 fixtures, 1,094,517 lines/side), carving mask (28 fixtures, 45,742 lines/side). - Final source rebuild is byte-identical to the measured candidate executable (SHA256 `1a7acdbb6af7e047c4adff6ef02176a4e24c330c380859bdf6ec4aaf9d1cf830`). - `python3 tools/pr_ready.py --base origin/main --quick` passes public-tree checks, formatting, workspace clippy and world tests. Python checks were skipped because Python is unchanged. The quick check omits the broader 307 affected parity suites; the three explicit fresh suites and complete differential corpus above cover this change's declared validation scope, not universal vanilla parity. Reproduction tooling and raw evidence are retained outside git at `/tmp/horizon-concurrency-20261018/{shared,carver}`. `shared/prepare_runner.py CHECKOUT` installs the same optional offset initialization, exact JSON timings and complete snapshot instrumentation on either revision. Build sequentially with: ```sh CARGO_TARGET_DIR=/srv/bob-data/horizon-concurrency-target cargo build --profile fast -p horizon-world --example concurrency_bench python3 /tmp/horizon-concurrency-20261018/shared/compare_outputs.py --baseline BASELINE --candidate CANDIDATE --out OUTPUT python3 /tmp/horizon-concurrency-20261018/shared/run_pairs.py --baseline BASELINE --candidate CANDIDATE --out OUTPUT --phase gate # Repeat into another output directory for the additional eight pairs. # Other phases: screen (3 pairs), scaling (3 pairs/count), large (5 pairs). ``` Resources: `/srv/bob-data/horizon/.local/horizon-client/26.3`. The preserved baseline executable is `shared/baseline-f422cbb7`; `commands.sh`, raw JSON, exact snapshot files/hashes, individual logs, executable hashes, and the complete local report are in `carver/`. Diagnostics and generated artifacts are excluded from the PR. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 16:00:11 +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#2929
No description provided.