[PR #1152] [MERGED] Advancement triggers test only the criteria that can pass; the log writes on its own thread #3098

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

📋 Pull Request Information

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

Base: main ← Head: perf/advancement-index-async-log


📝 Commits (2)

  • 815625e Advancement triggers test only the criteria that can pass; the log writes on its own thread
  • 3fdf210 Advancement index: measured on vanilla's tree

📊 Changes

3 files changed (+433 additions, -46 deletions)

View changed files

📝 crates/horizon-client/src/advancements.rs (+262 -0)
📝 crates/horizon-client/src/game/advancements.rs (+52 -7)
📝 crates/horizon-client/src/logging.rs (+119 -39)

📄 Description

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

What

Two main-thread costs found on the companion branch with HORIZON_SPIKES (060c795e, RESUME §2 9b; its companion and metering parts stay there):

  • Every inventory change tested all ~1,900 inventory_changed criteria, and every recipe unlocked all ~1,700 recipe_unlocked ones: 1.5-5 ms on such a tick. The tree now indexes inventory_changed criteria by the items that can pass them (tags resolved; the few without an item list always tried) and recipe_unlocked by recipe. Same answers: a criterion with an item-limited predicate can only pass with one of those items.
  • Each log line was an unbuffered stderr write plus a latest.log write under a mutex on the calling thread. The logger now formats the line on the calling thread and hands the I/O to a "Log writer" thread; flush() waits for it (crash report, exit).

Main-thread cost

None added: the index is built once with the tree (off the tick), and lookups replace the full scans.

Proof

Measured on vanilla's tree (ignored test index_on_vanilla_tree, HORIZON_RESOURCES, release, Mac mini): the tree loads in 136 ms; inventory_changed has 1914 criteria, the index builds in 0.75 ms, and a nine-stack inventory tests 67 of them (found in 16 µs); recipe_unlocked has 1739, an iron pickaxe tests 1. Unit tests inventory_index_keeps_the_criteria_the_items_could_pass, recipe_index_keeps_the_criteria_of_the_recipe.

Self-check

All 18 B5 branches merged on one integration commit over origin/main b31cb422 (Mac mini):

cargo fmt --all --check                                                  ok
set -o pipefail; cargo clippy --workspace --all-targets -- -D warnings   exit 0, no ^error
cargo test -p horizon-client                                             1087 passed, 0 failed
python3 tools/parity.py --changed origin/main                            102 passed, 0 failed (over b7390d78)
python3 tools/parity.py --changed-files <explosion.rs>                   22 passed, 0 failed (over b31cb422, after rebasing onto #1101)

tools/lan_e2e.py, full runs over b31cb422 (48 checks):

  • --server-thread: 47 passed; swings (the guest's hoe) failed after earlier checks and passes alone.
  • in-frame: 44 passed. cracks caught a guest's crack left behind when its own tick broke the block (fixed in the cracks PR; swings then cracks and a 3-break probe now pass in both modes). barter (piglin gone), swings and effects fail only after earlier checks and pass alone.
  • sign (not touched here) fails about 1 run in 4, on main too: place reports 2 ticks after the click, sometimes before the server's answer. Noted in FEATURES.md with the other flakes.

🤖 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/1152 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/22/2026 **Status:** ✅ Merged **Merged:** 10/22/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/advancement-index-async-log` --- ### 📝 Commits (2) - [`815625e`](https://github.com/horizon-rust/horizon/commit/815625e54731ee41e2dd2ffda887689220c2a99b) Advancement triggers test only the criteria that can pass; the log writes on its own thread - [`3fdf210`](https://github.com/horizon-rust/horizon/commit/3fdf210ccb736b19b45f4f76b27fc61fb9cdcd5d) Advancement index: measured on vanilla's tree ### 📊 Changes **3 files changed** (+433 additions, -46 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/advancements.rs` (+262 -0) 📝 `crates/horizon-client/src/game/advancements.rs` (+52 -7) 📝 `crates/horizon-client/src/logging.rs` (+119 -39) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What Two main-thread costs found on the companion branch with `HORIZON_SPIKES` (`060c795e`, RESUME §2 9b; its companion and metering parts stay there): - Every inventory change tested all ~1,900 `inventory_changed` criteria, and every recipe unlocked all ~1,700 `recipe_unlocked` ones: 1.5-5 ms on such a tick. The tree now indexes `inventory_changed` criteria by the items that can pass them (tags resolved; the few without an item list always tried) and `recipe_unlocked` by recipe. Same answers: a criterion with an item-limited predicate can only pass with one of those items. - Each log line was an unbuffered stderr write plus a `latest.log` write under a mutex on the calling thread. The logger now formats the line on the calling thread and hands the I/O to a "Log writer" thread; `flush()` waits for it (crash report, exit). ## Main-thread cost None added: the index is built once with the tree (off the tick), and lookups replace the full scans. ## Proof Measured on vanilla's tree (ignored test `index_on_vanilla_tree`, `HORIZON_RESOURCES`, release, Mac mini): the tree loads in 136 ms; `inventory_changed` has 1914 criteria, the index builds in 0.75 ms, and a nine-stack inventory tests 67 of them (found in 16 µs); `recipe_unlocked` has 1739, an iron pickaxe tests 1. Unit tests `inventory_index_keeps_the_criteria_the_items_could_pass`, `recipe_index_keeps_the_criteria_of_the_recipe`. ### Self-check All 18 B5 branches merged on one integration commit over origin/main `b31cb422` (Mac mini): ``` cargo fmt --all --check ok set -o pipefail; cargo clippy --workspace --all-targets -- -D warnings exit 0, no ^error cargo test -p horizon-client 1087 passed, 0 failed python3 tools/parity.py --changed origin/main 102 passed, 0 failed (over b7390d78) python3 tools/parity.py --changed-files <explosion.rs> 22 passed, 0 failed (over b31cb422, after rebasing onto #1101) ``` `tools/lan_e2e.py`, full runs over `b31cb422` (48 checks): - `--server-thread`: 47 passed; `swings` (the guest's hoe) failed after earlier checks and passes alone. - in-frame: 44 passed. `cracks` caught a guest's crack left behind when its own tick broke the block (fixed in the cracks PR; `swings` then `cracks` and a 3-break probe now pass in both modes). `barter` (piglin gone), `swings` and `effects` fail only after earlier checks and pass alone. - `sign` (not touched here) fails about 1 run in 4, on main too: `place` reports 2 ticks after the click, sometimes before the server's answer. Noted in FEATURES.md with the other flakes. 🤖 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-02 16:01:29 +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#3098
No description provided.