glb_skinning: avoid copying padded BIN data for every accessor #1754

Merged
kirigayakazima merged 1 commit from upstream-pr/1754 into main 2026-11-28 14:57:34 +00:00
kirigayakazima commented 2026-11-25 11:14:45 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-25T11:14:45Z.


Claimed in the coordination issue as: GLB-SKINNING-PADDED-BUFFER-COPIES

What and why

The analyzer copied each chunk before determining its purpose and sliced the BIN bytes down to the declared buffer length on each accessor read. With 1–3 bytes of alignment padding, each slice copied the entire buffer. Analysis now reads from a view of the original immutable bytes and enforces the existing declared-length checks. The public parse_glb helper still returns BIN bytes.

Tested

On the integration checkout a synthetic three-vertex model with a 16 MiB padded BIN and a 16 MiB extension chunk produced identical reports before and after. Starting tracemalloc after constructing the input, peak traced allocation during analysis fell from 33,562,127 to 8,532 bytes (Python 3.14.7). The regression uses smaller chunks and also checks that a buffer view cannot read into BIN padding.

  • python -I tests/test_glb_skinning.py passed all 28 tests on this branch (Windows, Python 3.14.7).
  • git diff --check and the repository game-data scan of all changed paths passed.
  • The five independent changes were also merged locally. Both affected test files passed together (50 tests) and the three character-model consumer suites passed (28 tests). The shared base at bcaa13da passed 6,287 semantic tests across 488 files.

GPUs tested: N/A (CPU-only asset tooling).
AI-assisted: Yes.

Checklist

  • Based on current upstream main.
  • One topic.
  • Only synthetic test fixtures. No game data, keys or decryption.
  • Translator contract table: N/A.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5490256429 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1754). Originally posted by [kirigayakazima](https://github.com/kirigayakazima) on 2026-11-25T11:14:45Z. --- Claimed in the coordination issue as: [GLB-SKINNING-PADDED-BUFFER-COPIES](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7160621714) ### What and why The analyzer copied each chunk before determining its purpose and sliced the BIN bytes down to the declared buffer length on each accessor read. With 1–3 bytes of alignment padding, each slice copied the entire buffer. Analysis now reads from a view of the original immutable bytes and enforces the existing declared-length checks. The public `parse_glb` helper still returns BIN bytes. ### Tested On the integration checkout a synthetic three-vertex model with a 16 MiB padded BIN and a 16 MiB extension chunk produced identical reports before and after. Starting tracemalloc after constructing the input, peak traced allocation during analysis fell from 33,562,127 to 8,532 bytes (Python 3.14.7). The regression uses smaller chunks and also checks that a buffer view cannot read into BIN padding. - `python -I tests/test_glb_skinning.py` passed all 28 tests on this branch (Windows, Python 3.14.7). - `git diff --check` and the repository game-data scan of all changed paths passed. - The five independent changes were also merged locally. Both affected test files passed together (50 tests) and the three character-model consumer suites passed (28 tests). The shared base at `bcaa13da` passed 6,287 semantic tests across 488 files. GPUs tested: N/A (CPU-only asset tooling). AI-assisted: Yes. ### Checklist - [x] Based on current upstream main. - [x] One topic. - [x] Only synthetic test fixtures. No game data, keys or decryption. - Translator contract table: N/A.
lixonik commented 2026-11-25 11:20:04 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-25T11:20:04Z.

Review: COMMENTED


Independent check at "0307e4c0". Windows: all 28 skinning tests passed. On a separate synthetic skinned triangle with a padded 16 MiB BIN and a 16 MiB extension chunk, the base and PR analysis reports matched. Peak Python-traced allocation during analysis dropped from 33,562,039 to 8,416 bytes. The public parse_glb helper still returned bytes.

AI-assisted review and CPU-only testing with synthetic inputs.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6056673755 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1754#pullrequestreview-6056673755). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-25T11:20:04Z. **Review:** COMMENTED --- Independent check at "0307e4c0". Windows: all 28 skinning tests passed. On a separate synthetic skinned triangle with a padded 16 MiB BIN and a 16 MiB extension chunk, the base and PR analysis reports matched. Peak Python-traced allocation during analysis dropped from 33,562,039 to 8,416 bytes. The public parse_glb helper still returned bytes. AI-assisted review and CPU-only testing with synthetic inputs.
zmasi commented 2026-11-28 11:53:14 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T11:53:14Z.


#1754 | head 0307e4c0fb (merged cleanly with main 24549bdb1) | python -I tests/test_glb_skinning.py | red on main: FAILED (failures=1) (AssertionError: 8401635 not less than 4194304 : inspection allocated a full unused payload) | green on PR+main: 34 tests OK | Windows 11, Python 3.12.10 | AI-assisted: yes

Audited _parse_chunks, parse_glb, _Reader.read, and analyze_glb in tools/glb_skinning.py (using a memoryview over the BIN chunk during analysis and unpacking directly from self.bin_chunk after view/accessor bounds exclude BIN alignment padding, while keeping parse_glb returning bytes for external callers). Also verified clean merge (0 conflicts) and combined execution with #1753 (36 tests OK), plus tests/test_ci_registration.py (18 OK), tests/test_text_write_line_endings.py (3 OK), and scripts/check_no_game_data.py.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238847793 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1754#issuecomment-7238847793). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T11:53:14Z. --- #1754 | head 0307e4c0fbd7e59e15b35063874011c80f78c5d7 (merged cleanly with main 24549bdb1) | `python -I tests/test_glb_skinning.py` | red on main: `FAILED (failures=1)` (`AssertionError: 8401635 not less than 4194304 : inspection allocated a full unused payload`) | green on PR+main: `34 tests OK` | Windows 11, Python 3.12.10 | AI-assisted: yes Audited `_parse_chunks`, `parse_glb`, `_Reader.read`, and `analyze_glb` in `tools/glb_skinning.py` (using a `memoryview` over the BIN chunk during analysis and unpacking directly from `self.bin_chunk` after view/accessor bounds exclude BIN alignment padding, while keeping `parse_glb` returning `bytes` for external callers). Also verified clean merge (`0` conflicts) and combined execution with #1753 (`36 tests OK`), plus `tests/test_ci_registration.py` (`18 OK`), `tests/test_text_write_line_endings.py` (`3 OK`), and `scripts/check_no_game_data.py`.
MoonEyes commented 2026-11-28 14:57:29 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T14:57:29Z.


Red/green: pytest tests/test_glb_skinning.py fails on main (1 failed, 27 passed, 23 subtests passed) and passes on head 0307e4c0fb merged with main (28 passed, 23 subtests passed).
Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main d48a957bb in GitHub Actions: no new failure.
AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7241070286 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1754#issuecomment-7241070286). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T14:57:29Z. --- Red/green: `pytest tests/test_glb_skinning.py` fails on main (1 failed, 27 passed, 23 subtests passed) and passes on head 0307e4c0fbd7 merged with main (28 passed, 23 subtests passed). Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main d48a957bb in GitHub Actions: no new failure. AI-assisted (Claude Code, Claude Opus 5.5)
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!1754
No description provided.