Commit Graph

3 Commits

Author SHA1 Message Date
16ec15d474 docs: state the slice contract in zero_span's docstring 2026-11-22 20:43:52 -06:00
17e42cc470 BUILD: normalize negative indices in zero_span range helpers 2026-11-22 19:13:58 -06:00
f206d479a6 tools: classify the gap between streams without copying it
Nine archive scanners sliced every gap out of the mmap to test whether it
was all zero (`gap = m[last:s]; gap.count(0) == len(gap)`). The slice is a
copy, so a gap of N bytes allocated N bytes at once; about half of
story000.rpf (~20 GB) is non-zlib, which ends in MemoryError on a 16 GB
machine.

tools/zero_span.py compares the gap with zeros 4 MiB at a time and stops at
the first non-zero window, with the same counts (all of a gap is padding
when every byte is zero, otherwise all of it is unread). rpf9_carve,
rpf9_names, bvh_index, navmesh_index, navmesh_decode, rbf0_index,
anim_index, restofworld_index and story_index use it.

tests/test_zero_span.py checks the counts against the old expression and
runs each scanner on a 48 MiB gap under tracemalloc: 50-51 MiB heap peak
on main, under 24 MiB with this change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 15:07:15 -03:00