[GH-ISSUE #3885] Function-tag resolution is O(n²) and re-runs every tick: a 20k-entry #tick tag freezes the tick for ~1.1 s #1130

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

Originally created by @ccclosed on GitHub (Oct 29, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/3885

🤖 Filed by ccclosed's AI agent (DeepSeek Harness, deepseek-v4.1-flash), not by ccclosed personally.

Severity: Medium — one tag can freeze the tick loop
Snapshot: origin/main 7c1e0f979 (2026-10-30)

What happens

Function-tag resolution is O(n²) and runs again on every server tick for #minecraft:tick / #minecraft:load and on every /function #tag call: entries are collected with a linear Vec::contains scan while appending.

  • crates/horizon-client-render/src/datapack.rs:480-502 — tag_functions (nested tag walk with linear dedupe; depth silently capped at 16, cycles undetected)
  • crates/horizon-client/src/game/functions.rs:232-262 — the caller that re-resolves #tick every tick

Measured: a 20 000-entry #minecraft:tick tag costs ≈ 1.10 s per resolution → one frozen tick, done again 20×/s.

Repro

Create data/minecraft/tags/function/tick.json with 20 000 entries pointing at a no-op function, join the world, watch the server tick hang. The audit's test datapack.rs tag_resolution_is_quadratic measures the same on the lib path.

Expected

Vanilla builds the tag's function set once per reload and resolves nested tags with cycle detection; the tick loop iterates a pre-built list.

Suggested fix

Resolve tags once at pack load/reload into BTreeSet/HashSet-backed lists, detect cycles/unbounded depth, and have the tick path iterate the cached list. (Also resolves the silent depth-16 truncation and cycles found by the same audit.)

Originally created by @ccclosed on GitHub (Oct 29, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/3885 > 🤖 Filed by ccclosed's AI agent (DeepSeek Harness, deepseek-v4.1-flash), not by ccclosed personally. **Severity:** Medium — one tag can freeze the tick loop **Snapshot:** `origin/main` `7c1e0f979` (2026-10-30) ### What happens Function-tag resolution is O(n²) and runs again on **every** server tick for `#minecraft:tick` / `#minecraft:load` and on every `/function #tag` call: entries are collected with a linear `Vec::contains` scan while appending. - `crates/horizon-client-render/src/datapack.rs:480-502` — `tag_functions` (nested tag walk with linear dedupe; depth silently capped at 16, cycles undetected) - `crates/horizon-client/src/game/functions.rs:232-262` — the caller that re-resolves `#tick` every tick Measured: a 20 000-entry `#minecraft:tick` tag costs ≈ **1.10 s per resolution** → one frozen tick, done again 20×/s. ### Repro Create `data/minecraft/tags/function/tick.json` with 20 000 entries pointing at a no-op function, join the world, watch the server tick hang. The audit's test `datapack.rs` `tag_resolution_is_quadratic` measures the same on the lib path. ### Expected Vanilla builds the tag's function set once per reload and resolves nested tags with cycle detection; the tick loop iterates a pre-built list. ### Suggested fix Resolve tags once at pack load/reload into `BTreeSet`/`HashSet`-backed lists, detect cycles/unbounded depth, and have the tick path iterate the cached list. (Also resolves the silent depth-16 truncation and cycles found by the same audit.)
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#1130
No description provided.