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

Merged
leonida/mandy
kirigayakazima merged 1 commit from codex/glb-skinning-padded-buffer-copies into main 2026-11-28 14:57:34 +00:00

Pull request successfully merged and closed

kirigayakazima commented 2026-11-25 11:14:45 +00:00

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.
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 reviewed 2026-11-25 11:20:04 +00:00
lixonik left a comment
No description provided.
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

#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.

#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

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)

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 description provided.