[PR #5570] [MERGED] horizon-prepare: fresh preparation about 2.5× faster (~40 s instead of ~105 s on 3 cores) with a lower memory peak #6361

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/5570
Author: @some-du6e
Created: 10/31/2026
Status: ✅ Merged
Merged: 11/1/2026
Merged by: @ludovic111

Base: main ← Head: perf/faster-prepare


📝 Commits (10+)

  • 78d211e horizon-prepare: run independent steps at once, skip unchanged exporters
  • a935fe0 horizon-prepare: run its JVMs as batch jobs (C1 only, ParallelGC)
  • a9d6eaf horizon-prepare: serial collector for its JVMs; time steps after compiling
  • 75047c9 horizon-prepare: cut its memory peak from 1.47 GB to 1.06 GB
  • c3e5e78 horizon-prepare: block behaviour on a second server JVM with 6+ cores
  • 9cecb86 horizon-prepare: review fixes for the parallel preparation
  • 5b16c46 horizon-prepare: the release check's repeat run compares the manifest too; four JVMs with the split
  • 39e9a8e horizon-prepare: a stamp without outputs never matches; say what HORIZON_PREPARE_JOBS limits
  • c6a4504 horizon-prepare: HORIZON_PREPARE_JOBS caps each step's threads
  • fd5f849 horizon-prepare test: ask the disk whether Tag.json and tag.json are one file

📊 Changes

12 files changed (+1254 additions, -565 deletions)

View changed files

📝 crates/horizon-prepare/src/artifacts.rs (+36 -33)
📝 crates/horizon-prepare/src/exporters.rs (+13 -5)
📝 crates/horizon-prepare/src/java.rs (+10 -1)
📝 crates/horizon-prepare/src/lib.rs (+933 -480)
➕ crates/horizon-prepare/src/pool.rs (+145 -0)
📝 crates/horizon-prepare/src/worker.rs (+3 -5)
📝 docs/launcher-preparation.md (+40 -4)
📝 docs/prepare-performance.md (+3 -1)
📝 mods/horizon/src/test/java/dev/horizonlab/parity/VanillaCollisionOracle.java (+11 -7)
📝 mods/horizon/src/test/java/dev/horizonlab/parity/VanillaGameplayFactsExporter.java (+15 -7)
📝 tests/test_prepare_exporters.py (+9 -7)
📝 tools/check_prepare_exporters.py (+36 -15)

📄 Description

horizon-prepare --prepare was slow on a fresh install. Every exporter JVM, the data generator and the asset copy ran one after another: about 105 s on a 3-core Linux box with the pinned 26.3 jars, peaking at 1.47 GB. Repeat runs also always started a server JVM, because the block behaviour and structure-block exporters had no skip check.

The output stays the same: tools/prepare_output.py gives the same digest, tools/check_prepare_exporters.py passes, and every pinned file is still hashed in full against research-lock.json.

What changed, one commit each:

  1. Independent steps run at once. There are four lanes:

    • the server worker's exporters, in their old order because they share state
    • the client worker, then the command registries
    • the data generator, then the creative tabs
    • the Rust-only copying

    At most three JVMs run at a time. A worker stops when its lane is done, and the two exporter sides compile in parallel. Hashing, asset extraction, structure templates, library unpacking and inventories use several threads. The block behaviour and structure-block exporters now keep a stamp.json in .local/, so an unchanged repeat run starts no JVM. HORIZON_PREPARE_JOBS=1 keeps everything serial.

  2. The JVMs run as batch jobs with -XX:TieredStopAtLevel=1, which javac gets too through -J. Short JVMs side by side lose more CPU to C2 than it wins back: 105 s became 67 s.

  3. The serial collector. It was as fast as the parallel one here (63–66 s) and keeps the three concurrent heaps at 1.25 GB together instead of 2 GB. Steps are timed after compiling.

  4. The memory peak drops from 1.47 GB to 1.06 GB.

    • Inside the worker, the collision exporter skips its 62 MB of verification inputs, which only the parity harness reads; standalone runs still write them.
    • The gameplay facts exporter streams its 56 MB file instead of building it as a tree, then a String. The bytes are the same.
    • Threads reading one jar share one parsed member list through clones of ZipArchive, each reading at its own offset.

    The server worker goes from 1.25 GB to ~480 MB.

  5. With 6+ cores, the world generator's block behaviour and the structure blocks run in a second server JVM on a fifth lane. On a 6-core laptop, the other lanes finished at ~17 s and the server lane then ran alone for ~20 s more. The split costs a second Bootstrap and ~400 MB, so it stays off below 6 cores. Forced on the 3-core box it was slower (44.9 s vs 40.5 s); on 6+ cores it hasn't been timed yet. The release check now runs its batched preparation with HORIZON_PREPARE_JOBS=6 and expects 6 JVM launches.

The result: a fresh preparation takes ~40 s instead of ~105 s on the 3-core box. A player on a 6-core Mac reports ~41 s with the first four commits.

Upstream's --progress json still reports its 18 stages. The lanes send them to the caller's thread, which counts them, so the fraction only goes up. The rest of the new main ported as-is: --output, named inputs, folder locks, the --check stamp, and zip 9's fallible file_names.

Review fixes, from four review rounds:

  • A failed exporter compile now fails every lane at once instead of being retried by each one.
  • The gameplay facts exporter writes to a .partial file and moves it into place, so a stopped run can't leave a short file for the next run to keep.
  • A stamp that records no outputs never matches.
  • pool and the progress relay are tested at 1 job and at several.

The release check now runs a third batched preparation with HORIZON_PREPARE_JOBS=2, which is the path most machines take (5 JVMs). It then repeats that run, which must start no JVM and leave every file and the manifest unchanged.

Live test, release build, the pinned 26.3 jars, a shared machine under load (load average ~18–21):

  • Fresh: this branch took 216 s, main 572 s. Both produce digest 02ae903f… (23,062 files), so the output is the same. It differs from output-versions.txt's version 3 only because this machine's Minecraft copy differs from CI's.
  • Repeat: no exporter or JVM ran.
  • A server jar that doesn't match the pin: fails right away with the sha1 mismatch and writes nothing.

Checks: cargo test -p horizon-prepare, clippy -D warnings, cargo fmt --check, python3 -m unittest tests.test_prepare_exporters.

It's over the ~500-line guideline. Most of it is commit 1 reshaping steps into lanes; each commit stands on its own.

Note

Filed by Opus 5.5 using 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/5570 **Author:** [@some-du6e](https://github.com/some-du6e) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/faster-prepare` --- ### 📝 Commits (10+) - [`78d211e`](https://github.com/horizon-rust/horizon/commit/78d211e0a45d8c84d07760349ac72ff9e9dbaef1) horizon-prepare: run independent steps at once, skip unchanged exporters - [`a935fe0`](https://github.com/horizon-rust/horizon/commit/a935fe0bf2a33515e29268c7edbf8396c7b01055) horizon-prepare: run its JVMs as batch jobs (C1 only, ParallelGC) - [`a9d6eaf`](https://github.com/horizon-rust/horizon/commit/a9d6eaf3b38522d2adf763a86274fe0a661d1bde) horizon-prepare: serial collector for its JVMs; time steps after compiling - [`75047c9`](https://github.com/horizon-rust/horizon/commit/75047c93d9f31803cd17b0fc71e1d8b85e5e4efe) horizon-prepare: cut its memory peak from 1.47 GB to 1.06 GB - [`c3e5e78`](https://github.com/horizon-rust/horizon/commit/c3e5e7866c3a5f5c7b6ddb137fe4525f1fcbb32d) horizon-prepare: block behaviour on a second server JVM with 6+ cores - [`9cecb86`](https://github.com/horizon-rust/horizon/commit/9cecb86ec22d31c9a907673863218dbcaf8410f1) horizon-prepare: review fixes for the parallel preparation - [`5b16c46`](https://github.com/horizon-rust/horizon/commit/5b16c46f5dbc48e94d33ecbff6a94a94b6680efb) horizon-prepare: the release check's repeat run compares the manifest too; four JVMs with the split - [`39e9a8e`](https://github.com/horizon-rust/horizon/commit/39e9a8e0d1213b76825f526d32c634539250cdef) horizon-prepare: a stamp without outputs never matches; say what HORIZON_PREPARE_JOBS limits - [`c6a4504`](https://github.com/horizon-rust/horizon/commit/c6a450499be954f6614bb81e01efe8d9c51ae6b1) horizon-prepare: HORIZON_PREPARE_JOBS caps each step's threads - [`fd5f849`](https://github.com/horizon-rust/horizon/commit/fd5f849c4217de988fbcd8464dacdfda0326c099) horizon-prepare test: ask the disk whether Tag.json and tag.json are one file ### 📊 Changes **12 files changed** (+1254 additions, -565 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-prepare/src/artifacts.rs` (+36 -33) 📝 `crates/horizon-prepare/src/exporters.rs` (+13 -5) 📝 `crates/horizon-prepare/src/java.rs` (+10 -1) 📝 `crates/horizon-prepare/src/lib.rs` (+933 -480) ➕ `crates/horizon-prepare/src/pool.rs` (+145 -0) 📝 `crates/horizon-prepare/src/worker.rs` (+3 -5) 📝 `docs/launcher-preparation.md` (+40 -4) 📝 `docs/prepare-performance.md` (+3 -1) 📝 `mods/horizon/src/test/java/dev/horizonlab/parity/VanillaCollisionOracle.java` (+11 -7) 📝 `mods/horizon/src/test/java/dev/horizonlab/parity/VanillaGameplayFactsExporter.java` (+15 -7) 📝 `tests/test_prepare_exporters.py` (+9 -7) 📝 `tools/check_prepare_exporters.py` (+36 -15) </details> ### 📄 Description `horizon-prepare --prepare` was slow on a fresh install. Every exporter JVM, the data generator and the asset copy ran one after another: about 105 s on a 3-core Linux box with the pinned 26.3 jars, peaking at 1.47 GB. Repeat runs also always started a server JVM, because the block behaviour and structure-block exporters had no skip check. The output stays the same: `tools/prepare_output.py` gives the same digest, `tools/check_prepare_exporters.py` passes, and every pinned file is still hashed in full against `research-lock.json`. What changed, one commit each: 1. **Independent steps run at once.** There are four lanes: - the server worker's exporters, in their old order because they share state - the client worker, then the command registries - the data generator, then the creative tabs - the Rust-only copying At most three JVMs run at a time. A worker stops when its lane is done, and the two exporter sides compile in parallel. Hashing, asset extraction, structure templates, library unpacking and inventories use several threads. The block behaviour and structure-block exporters now keep a `stamp.json` in `.local/`, so **an unchanged repeat run starts no JVM**. `HORIZON_PREPARE_JOBS=1` keeps everything serial. 2. **The JVMs run as batch jobs** with `-XX:TieredStopAtLevel=1`, which javac gets too through `-J`. Short JVMs side by side lose more CPU to C2 than it wins back: 105 s became 67 s. 3. **The serial collector.** It was as fast as the parallel one here (63–66 s) and keeps the three concurrent heaps at 1.25 GB together instead of 2 GB. Steps are timed after compiling. 4. **The memory peak drops from 1.47 GB to 1.06 GB.** - Inside the worker, the collision exporter skips its 62 MB of verification inputs, which only the parity harness reads; standalone runs still write them. - The gameplay facts exporter streams its 56 MB file instead of building it as a tree, then a String. The bytes are the same. - Threads reading one jar share one parsed member list through clones of `ZipArchive`, each reading at its own offset. The server worker goes from 1.25 GB to ~480 MB. 5. **With 6+ cores, the world generator's block behaviour and the structure blocks run in a second server JVM on a fifth lane.** On a 6-core laptop, the other lanes finished at ~17 s and the server lane then ran alone for ~20 s more. The split costs a second Bootstrap and ~400 MB, so it stays off below 6 cores. Forced on the 3-core box it was slower (44.9 s vs 40.5 s); on 6+ cores it hasn't been timed yet. The release check now runs its batched preparation with `HORIZON_PREPARE_JOBS=6` and expects 6 JVM launches. The result: a fresh preparation takes ~40 s instead of ~105 s on the 3-core box. A player on a 6-core Mac reports ~41 s with the first four commits. Upstream's `--progress json` still reports its 18 stages. The lanes send them to the caller's thread, which counts them, so the fraction only goes up. The rest of the new main ported as-is: `--output`, named inputs, folder locks, the `--check` stamp, and zip 9's fallible `file_names`. Review fixes, from four review rounds: - A failed exporter compile now fails every lane at once instead of being retried by each one. - The gameplay facts exporter writes to a `.partial` file and moves it into place, so a stopped run can't leave a short file for the next run to keep. - A stamp that records no outputs never matches. - `pool` and the progress relay are tested at 1 job and at several. The release check now runs a third batched preparation with `HORIZON_PREPARE_JOBS=2`, which is the path most machines take (5 JVMs). It then repeats that run, which must start no JVM and leave every file and the manifest unchanged. Live test, release build, the pinned 26.3 jars, a shared machine under load (load average ~18–21): - **Fresh:** this branch took 216 s, main 572 s. Both produce digest `02ae903f…` (23,062 files), so the output is the same. It differs from `output-versions.txt`'s version 3 only because this machine's Minecraft copy differs from CI's. - **Repeat:** no exporter or JVM ran. - **A server jar that doesn't match the pin:** fails right away with the sha1 mismatch and writes nothing. Checks: `cargo test -p horizon-prepare`, clippy `-D warnings`, `cargo fmt --check`, `python3 -m unittest tests.test_prepare_exporters`. It's over the ~500-line guideline. Most of it is commit 1 reshaping `steps` into lanes; each commit stands on its own. > [!NOTE] > Filed by Opus 5.5 using 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:19:12 +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#6361
No description provided.