[PR #406] [MERGED] Reopening a world no longer duplicates its entities #2540

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

📋 Pull Request Information

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

Base: main ← Head: fix/world-reopen-entities


📝 Commits (1)

  • b5a7138 Reopening a world no longer duplicates its entities (#374)

📊 Changes

2 files changed (+131 additions, -14 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+29 -14)
➕ tools/test_world_reopen_parity.py (+102 -0)

📄 Description

Fixes #374

What was leaking

Save and Quit to Title kept every non-mob entity (minecarts, boats, armor stands, item frames, paintings, crystals, other entities) in memory. Opening the world again loaded them from disk a second time, and the next save wrote both copies under new UUIDs. Each join/leave doubled them. In a seed-1 world the mineshaft chest minecarts went 3 → 384 after 8 cycles, then 768 → 1536 → 3072. sample of the laggy game showed tick_cart, collision scans and EntityBatch::update spending their time on those copies. Threads and GPU sections stayed flat (23 threads, 988 sections every cycle), so nothing else was leaking.

Fix

Game::clear_entities lets go of every entity of the level: mobs, items, orbs, projectiles, falling blocks, TNT, boats, carts, armor stands, frames, paintings, other entities, the dragon and its crystals, fireballs and breath, tridents, rockets, bolts, particles and pickups. It also clears the ridden vehicle and the entity memory. close_world calls it after the save, and open_world calls it in place of its partial list. Vanilla does the same: MinecraftServer.stopServer saves, then closes every ServerLevel, whose PersistentEntitySectionManager unloads its entities with it. A reopened world starts empty and loads its entities once.

Worlds that were already reopened many times keep the extra copies on disk. They have distinct UUIDs, so they can't be told apart from real entities. /kill @e[type=minecraft:chest_minecart] (or the kind that piled up) clears them.

Verified

  • New harness tools/test_world_reopen_parity.py. It launches the game offscreen, summons a minecart next to the mineshaft chest minecarts of seed 7, then quits to the title and reopens three times. The list of minecarts must stay the same.
    • before (main): minecarts: 4 → reopen 1: 8 FAIL, reopen 2: 16 FAIL, reopen 3: 32 FAIL
    • after: reopen 1: 4 minecarts ok … reopen 3: 4 minecarts ok, world reopen: PASS
  • Reproduced in the game first with horizon-ctl (open → pause → click-button "Save and Quit to Title" loop): the cart counts above, with stable thread counts.

Self-check (combined branch of the batch's seven PRs, #406 #407 #409 #414 #416 #421 #423, on origin/main d28521f7; Mac mini):

  • cargo fmt --all --check: ok
  • cargo clippy --workspace --all-targets -- -D warnings: ok
  • cargo test -p horizon-client: 775 passed, 0 failed
  • tools/parity.py --changed origin/main (82 harnesses, including the new world_reopen): 82 pass.
    • The first pass found two #407 regressions, both fixed in #407 and rerun green: command_parse (suggestions were pruned in brigadier itself rather than only in the player's chat) and dedicated_server (dedicated-server guests lost their ops-based commands).
    • 34 harnesses passed on the combined commit before those two #407 fixes. The other 48 plus the two reruns passed after them.
  • Not run: the Linux and Windows checks (this batch was developed and checked on the Mac mini only).

🤖 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/406 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/15/2026 **Status:** ✅ Merged **Merged:** 10/16/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/world-reopen-entities` --- ### 📝 Commits (1) - [`b5a7138`](https://github.com/horizon-rust/horizon/commit/b5a713848902a04778bbb64bb1b2ba26f94d4ed1) Reopening a world no longer duplicates its entities (#374) ### 📊 Changes **2 files changed** (+131 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+29 -14) ➕ `tools/test_world_reopen_parity.py` (+102 -0) </details> ### 📄 Description Fixes #374 ## What was leaking Save and Quit to Title kept every **non-mob entity** (minecarts, boats, armor stands, item frames, paintings, crystals, other entities) in memory. Opening the world again loaded them from disk a second time, and the next save wrote both copies under new UUIDs. Each join/leave **doubled** them. In a seed-1 world the mineshaft chest minecarts went 3 → 384 after 8 cycles, then 768 → 1536 → 3072. `sample` of the laggy game showed `tick_cart`, collision scans and `EntityBatch::update` spending their time on those copies. Threads and GPU sections stayed flat (23 threads, 988 sections every cycle), so nothing else was leaking. ## Fix `Game::clear_entities` lets go of every entity of the level: mobs, items, orbs, projectiles, falling blocks, TNT, boats, carts, armor stands, frames, paintings, other entities, the dragon and its crystals, fireballs and breath, tridents, rockets, bolts, particles and pickups. It also clears the ridden vehicle and the entity memory. `close_world` calls it after the save, and `open_world` calls it in place of its partial list. Vanilla does the same: `MinecraftServer.stopServer` saves, then closes every `ServerLevel`, whose `PersistentEntitySectionManager` unloads its entities with it. A reopened world starts empty and loads its entities once. Worlds that were already reopened many times keep the extra copies on disk. They have distinct UUIDs, so they can't be told apart from real entities. `/kill @e[type=minecraft:chest_minecart]` (or the kind that piled up) clears them. ## Verified - New harness `tools/test_world_reopen_parity.py`. It launches the game offscreen, summons a minecart next to the mineshaft chest minecarts of seed 7, then quits to the title and reopens three times. The list of minecarts must stay the same. - before (main): `minecarts: 4` → `reopen 1: 8 FAIL`, `reopen 2: 16 FAIL`, `reopen 3: 32 FAIL` - after: `reopen 1: 4 minecarts ok` … `reopen 3: 4 minecarts ok`, `world reopen: PASS` - Reproduced in the game first with horizon-ctl (`open` → `pause` → `click-button "Save and Quit to Title"` loop): the cart counts above, with stable thread counts. **Self-check** (combined branch of the batch's seven PRs, #406 #407 #409 #414 #416 #421 #423, on origin/main d28521f7; Mac mini): - `cargo fmt --all --check`: ok - `cargo clippy --workspace --all-targets -- -D warnings`: ok - `cargo test -p horizon-client`: 775 passed, 0 failed - `tools/parity.py --changed origin/main` (82 harnesses, including the new `world_reopen`): 82 pass. - The first pass found two #407 regressions, both fixed in #407 and rerun green: `command_parse` (suggestions were pruned in brigadier itself rather than only in the player's chat) and `dedicated_server` (dedicated-server guests lost their ops-based commands). - 34 harnesses passed on the combined commit before those two #407 fixes. The other 48 plus the two reruns passed after them. - Not run: the Linux and Windows checks (this batch was developed and checked on the Mac mini only). 🤖 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 15:57:01 +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#2540
No description provided.