[PR #6061] [MERGED] Keep advancement criteria's conditions as JSON, read on first test (−4 MB idle) #6636

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/6061
Author: @ludovic111
Created: 11/1/2026
Status: ✅ Merged
Merged: 11/1/2026
Merged by: @ludovic111

Base: main ← Head: perf/lazy-advancement-criteria


📝 Commits (1)

  • c124903 Keep advancement criteria's conditions as JSON, read on first test

📊 Changes

2 files changed (+12 additions, -7 deletions)

View changed files

📝 crates/horizon-client/src/advancements.rs (+11 -6)
📝 crates/horizon-client/src/game/advancements.rs (+1 -1)

📄 Description

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

Follows #6041 (LazyJson, merged).

What

The advancement tree (advancements::Tree, shared by a server's advancement packets and its game's criteria) held every criterion's conditions as a serde_json::Value: vanilla's ~1,870 advancements (~1,740 of them recipe advancements) have ~7,000 JSON objects in their criteria, a B-tree node each as a Value, ~4 MB of an idle server's heap, and most criteria are never tested in a game.

Criterion.conditions is now a LazyJson (#6041): the criterion's JSON text, read into a Value the first time it is tested and kept from then on. It derefs to Value, so the tests (conditions["items"], &criterion.conditions, is_null()) are unchanged.

  • The two indexes built over every criterion (recipe_unlocked by recipe, inventory_changed by item) read each one with LazyJson::read, which does not keep it: building them reads every criterion once, as before, but keeps none.
  • A criterion read for the first time costs a parse of a few hundred bytes (µs); the index already limits an inventory change to the criteria of the items it holds.

Measured

playhorizon, --cpus 0-3 --exclusive, dedicated server, new world, fresh data folders per start, MIMALLOC_ALLOW_THP=0, alternated (main 5bbecdc49, #6041, this PR on #6041), idle 32 s after Done.

main #6041 this PR
idle anonymous memory (4 starts each) 185.1 / 184.9 / 185.1 / 186.1 MB 178.4 / 179.1 / 179.8 / 179.7 MB 174.9 / 175.4 / 175.3 / 174.7 MB (−4.1 MB against #6041, every start)
idle RSS 223.3 / 223.3 / 223.4 / 225.1 MB 217.3 / 217.5 / 218.2 / 219.1 MB 213.1 / 213.9 / 213.8 / 212.8 MB
Done 2.021 / 1.924 / 1.915 / 1.894 s 1.900 / 1.918 / 1.896 / 2.019 s 1.902 / 1.885 / 1.850 / 1.862 s
20 bots, MSPT (2 alternated rounds) 29.25 / 26.75 28.54 / 26.92 27.12 / 28.44 (same)

Tests

  • The index tests (inventory_index_keeps_the_criteria_the_items_could_pass, recipe_index_keeps_the_criteria_of_the_recipe) build their trees from LazyJson conditions and pass; the advancement tests pass (cargo test -p horizon-client --lib advancements: 12).
  • cargo clippy --workspace --all-targets -- -D warnings, cargo fmt --check: clean (Mac).

pr_ready (tools/pr_ready.py --quick on playhorizon, against origin/main at 8c02c0b85 — with #6041, then unmerged —, 19 min 55 s)

Check Result
Scope ✅ 6 files, +178 −20 (with #6041's)
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ❌ 515 run, FAILED (failures=2, skipped=1) (55 s)
rustfmt ❌ failed (1 s)
clippy ❌ failed
tests: horizon-client, horizon-items, horizon-world ✅ 2099 passed (14 min 42 s)
doc tests ✅ 0 passed (4 s)
content root tests ✅ 21 passed (4 min 2 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 339 affected, to run in CI (--quick)
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

Notes: playhorizon's toolchain has no rustfmt/clippy, so both ran on the Mac (clean). The two Python failures are that host's virtual-screen tests (OK on the Mac). Players see no change: skip-release.

🤖 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/6061 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/lazy-advancement-criteria` --- ### 📝 Commits (1) - [`c124903`](https://github.com/horizon-rust/horizon/commit/c12490337fd45df25da14a6c5006a72b8ec4cac3) Keep advancement criteria's conditions as JSON, read on first test ### 📊 Changes **2 files changed** (+12 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/advancements.rs` (+11 -6) 📝 `crates/horizon-client/src/game/advancements.rs` (+1 -1) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Follows #6041 (`LazyJson`, merged). ## What The advancement tree (`advancements::Tree`, shared by a server's advancement packets and its game's criteria) held every criterion's `conditions` as a `serde_json::Value`: vanilla's ~1,870 advancements (~1,740 of them recipe advancements) have ~7,000 JSON objects in their criteria, a B-tree node each as a `Value`, ~4 MB of an idle server's heap, and most criteria are never tested in a game. `Criterion.conditions` is now a `LazyJson` (#6041): the criterion's JSON text, read into a `Value` the first time it is tested and kept from then on. It derefs to `Value`, so the tests (`conditions["items"]`, `&criterion.conditions`, `is_null()`) are unchanged. - The two indexes built over every criterion (`recipe_unlocked` by recipe, `inventory_changed` by item) read each one with `LazyJson::read`, which does not keep it: building them reads every criterion once, as before, but keeps none. - A criterion read for the first time costs a parse of a few hundred bytes (µs); the index already limits an inventory change to the criteria of the items it holds. ## Measured playhorizon, `--cpus 0-3 --exclusive`, dedicated server, new world, fresh data folders per start, `MIMALLOC_ALLOW_THP=0`, alternated (main 5bbecdc49, #6041, this PR on #6041), idle 32 s after Done. | | main | #6041 | this PR | |---|---|---|---| | idle anonymous memory (4 starts each) | 185.1 / 184.9 / 185.1 / 186.1 MB | 178.4 / 179.1 / 179.8 / 179.7 MB | **174.9 / 175.4 / 175.3 / 174.7 MB** (−4.1 MB against #6041, every start) | | idle RSS | 223.3 / 223.3 / 223.4 / 225.1 MB | 217.3 / 217.5 / 218.2 / 219.1 MB | **213.1 / 213.9 / 213.8 / 212.8 MB** | | Done | 2.021 / 1.924 / 1.915 / 1.894 s | 1.900 / 1.918 / 1.896 / 2.019 s | 1.902 / 1.885 / 1.850 / 1.862 s | | 20 bots, MSPT (2 alternated rounds) | 29.25 / 26.75 | 28.54 / 26.92 | 27.12 / 28.44 (same) | ## Tests - The index tests (`inventory_index_keeps_the_criteria_the_items_could_pass`, `recipe_index_keeps_the_criteria_of_the_recipe`) build their trees from `LazyJson` conditions and pass; the advancement tests pass (`cargo test -p horizon-client --lib advancements`: 12). - `cargo clippy --workspace --all-targets -- -D warnings`, `cargo fmt --check`: clean (Mac). **pr_ready** (`tools/pr_ready.py --quick` on playhorizon, against origin/main at 8c02c0b85 — with #6041, then unmerged —, 19 min 55 s) | Check | Result | | --- | --- | | Scope | ✅ 6 files, +178 −20 (with #6041's) | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ❌ 515 run, FAILED (failures=2, skipped=1) (55 s) | | rustfmt | ❌ failed (1 s) | | clippy | ❌ failed | | tests: horizon-client, horizon-items, horizon-world | ✅ 2099 passed (14 min 42 s) | | doc tests | ✅ 0 passed (4 s) | | content root tests | ✅ 21 passed (4 min 2 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 339 affected, to run in CI (--quick) | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | Notes: playhorizon's toolchain has no rustfmt/clippy, so both ran on the Mac (clean). The two Python failures are that host's virtual-screen tests (OK on the Mac). Players see no change: `skip-release`. 🤖 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 06:24: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#6636
No description provided.