[PR #735] [MERGED] OLD-9481: restore old upstream PR 9481 - world_build: drop a staged chunk PNG once no later chunk uses it #774

Closed
opened 2026-11-26 20:19:00 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/735
Author: @aslan2142
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/25/2026
Merged by: @aslan2142

Base: main ← Head: world-build-png-budget


📝 Commits (1)

  • 198b5c5 world_build: drop a staged chunk PNG once no later chunk uses it (BUILD-WORLD-BAKED-PNG-BUDGET)

📊 Changes

2 files changed (+195 additions, -26 deletions)

View changed files

📝 tests/test_world_build.py (+150 -0)
📝 tools/world_build.py (+45 -26)

📄 Description

Claimed in the coordination issue as: OLD-9481 https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7132371964

Restoration of my original pull request, old upstream PR 9481 in ItsNotRexed/Leonida, which was closed unmerged when that repository went private on 2026-11-23 (old numbers link nowhere now). Rebased onto main at 9600cf0c64; the commit applies unchanged, since tools/world_build.py and tests/test_world_build.py have not changed on main since the original base.

What and why

  • The problem: _build_staged_world in tools/world_build.py (the spatial, grid and baked-placement builds) keeps every decoded chunk PNG in its single-flight cache until the build returns. The PNGs held grow with the chunk count.
  • The fix: before any chunk is written, the build counts how many chunks use each texture. A decoded PNG leaves the cache when its last chunk takes it.
  • What stays the same:
    • each texture is still decoded once per build;
    • threads waiting on a decode still share it, through a small _SharedPng (an event plus the bytes);
    • the chunks and world.json are byte-identical.
  • Tests: StagedPngRetentionTest in tests/test_world_build.py, on synthetic chunks with uniform 4x4 DDS textures:
    • the PNGs held stay flat from 8 to 24 chunks (spatial, 1 worker);
    • a 4-worker build stays bounded and matches the serial build;
    • the grid layout releases every PNG that no later chunk uses.

Tested

Linux, Python 3.14.10, CPU only, synthetic inputs (no game files):

  • python -I tests/test_world_build.py:

    • on main with this PR's tests: 68 run, 1 skipped, the 4 new retention tests fail (26 PNGs still held at the last chunk);
    • on this branch: 68 run, 1 skipped, all pass.
  • A synthetic 24-chunk build on main and on this branch:

    • the whole output has the same SHA-256 on both, for 1 and 4 workers;
    • each texture is decoded 26 times on both, and none is left after the build.

    Decoded PNGs held while each chunk is written (main → this branch):

    Layout, workers At the last chunk Peak
    spatial, 1 26 → 3 26 → 3
    spatial, 4 26 → 6 26 → 7
    grid, 1 26 → 3 26 → 11
    grid, 4 26 → 8 26 → 14

    The 4-worker counts depend on thread timing.

  • python -m compileall -q tools tests, git diff --check, and python -I scripts/check_no_game_data.py on both changed files: all clean.

  • On the old repository, the original pull request had five independent checks: Linux, a four-worker concurrency run, and Windows on Python 3.11 and 3.13.

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

AI-assisted (Claude Code, Claude Opus 5.5).


🔄 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/ubiquitarianism/leonida/pull/735 **Author:** [@aslan2142](https://github.com/aslan2142) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/25/2026 **Merged by:** [@aslan2142](https://github.com/aslan2142) **Base:** `main` ← **Head:** `world-build-png-budget` --- ### 📝 Commits (1) - [`198b5c5`](https://github.com/ubiquitarianism/leonida/commit/198b5c5bcdd5c17934da836dceacb97dcb3c3cbd) world_build: drop a staged chunk PNG once no later chunk uses it (BUILD-WORLD-BAKED-PNG-BUDGET) ### 📊 Changes **2 files changed** (+195 additions, -26 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_world_build.py` (+150 -0) 📝 `tools/world_build.py` (+45 -26) </details> ### 📄 Description Claimed in the coordination issue as: OLD-9481 https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7132371964 Restoration of my original pull request, old upstream PR 9481 in `ItsNotRexed/Leonida`, which was closed unmerged when that repository went private on 2026-11-23 (old numbers link nowhere now). Rebased onto main at 9600cf0c648a8b2c4ce18521e416815d3d43eeb2; the commit applies unchanged, since `tools/world_build.py` and `tests/test_world_build.py` have not changed on main since the original base. ### What and why - **The problem:** `_build_staged_world` in `tools/world_build.py` (the spatial, grid and baked-placement builds) keeps every decoded chunk PNG in its single-flight cache until the build returns. The PNGs held grow with the chunk count. - **The fix:** before any chunk is written, the build counts how many chunks use each texture. A decoded PNG leaves the cache when its last chunk takes it. - **What stays the same:** - each texture is still decoded once per build; - threads waiting on a decode still share it, through a small `_SharedPng` (an event plus the bytes); - the chunks and `world.json` are byte-identical. - **Tests:** `StagedPngRetentionTest` in `tests/test_world_build.py`, on synthetic chunks with uniform 4x4 DDS textures: - the PNGs held stay flat from 8 to 24 chunks (spatial, 1 worker); - a 4-worker build stays bounded and matches the serial build; - the grid layout releases every PNG that no later chunk uses. ### Tested Linux, Python 3.14.10, CPU only, synthetic inputs (no game files): - `python -I tests/test_world_build.py`: - on main with this PR's tests: 68 run, 1 skipped, the 4 new retention tests fail (26 PNGs still held at the last chunk); - on this branch: 68 run, 1 skipped, all pass. - A synthetic 24-chunk build on main and on this branch: - the whole output has the same SHA-256 on both, for 1 and 4 workers; - each texture is decoded 26 times on both, and none is left after the build. Decoded PNGs held while each chunk is written (main → this branch): | Layout, workers | At the last chunk | Peak | | --- | --- | --- | | spatial, 1 | 26 → 3 | 26 → 3 | | spatial, 4 | 26 → 6 | 26 → 7 | | grid, 1 | 26 → 3 | 26 → 11 | | grid, 4 | 26 → 8 | 26 → 14 | The 4-worker counts depend on thread timing. - `python -m compileall -q tools tests`, `git diff --check`, and `python -I scripts/check_no_game_data.py` on both changed files: all clean. - On the old repository, the original pull request had five independent checks: Linux, a four-worker concurrency run, and Windows on Python 3.11 and 3.13. GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change) AI-assisted (Claude Code, Claude Opus 5.5). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:19:00 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
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
starred/leonida#774
No description provided.