Repository navigation
Conversation
…UILD-1222) A full levels.rpf `rpf9dump models` manifest is 5.1 GB, and json.load of it took the process to 20.6 GB RAM. read_items() now reads the manifest in 1 MB chunks, decodes one item at a time and keeps only the fields the tool reads (Offset, File, Name, MeshTris, MeshModels, MeshGeoms, MeshShaders and each material's Shader, in place). Other top-level members are decoded and dropped. A broken manifest is a ValueError, so main() still prints one line and exits 2. On a 102 MB synthetic manifest (40,000 items) the peak Python memory goes from 730 MB to 63 MB at the same speed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Tested 2a07d70 on Windows, CPython 3.14.7, CPU only (no GPU, no game files). I used synthetic inputs only.
I found one defect in the streaming reader. It refuses a valid JSON number when the first 1 MiB chunk ends at the exponent marker. When I move the same number by one space, the command succeeds. The merge base (03b09a0) accepts the two files. Run this script from the repository root: import json, runpy, tempfile
from pathlib import Path
t = runpy.run_path("tests/test_bvh_match.py")
with tempfile.TemporaryDirectory() as tmp:
d = Path(tmp)
blas = d / "blas.bin"
blas.write_bytes(t["build"](t["LEAVES"], bounds=t["BOUNDS"])[0])
t["write_obj"](d / "a.obj", [t["group"](2)])
rows = json.dumps([t["item"](0, "a.obj", [2])])
for extra in (0, 1):
prefix = '{"Scale":'
s = prefix + " " * ((1 << 20) - len(prefix) - 2 + extra) + '1e2,"Items":' + rows + '}'
assert json.loads(s)["Scale"] == 100
path = d / "manifest.json"
path.write_text(s, encoding="ascii")
print(extra, t["M"].main([str(blas), str(path)]))Actual result: exit status 2 for Cause: AI-assisted. |
Kam471
left a comment
There was a problem hiding this comment.
Ran this at 2a07d70a on Windows 11: python -I tests/test_bvh_match.py -> 22 tests, OK; compileall and git diff --check clean.
The manifest Items are now streamed instead of loaded whole, and the new cases cover the truncated/duplicate/large-manifest paths while the existing matching tests pass. No blocking issue.
|
Tested
AI-assisted review. |
Review of ItsNotRexed#4310 (shdann): when the first 1 MiB chunk ended at the exponent marker, raw_decode returned 1 for 1e|2 and the reader then failed on e. A top-level scalar now has to end at least SCALAR_TAIL characters before the buffer's end (or at end of file); otherwise the next chunk is read and the value decoded again. Items are objects, so their numbers were never affected. A test tries six numbers (exponents, signs, a 20-digit integer) at every alignment against 5-, 7-, 11- and 13-character chunks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@shdann thanks, that's a real bug and a very clear repro. Fixed in f57e683: a top-level scalar now has to end at least 32 characters before the end of the buffer (or at end of file), otherwise the reader takes the next chunk and decodes the value again. Items themselves are objects, so their numbers were never at risk.
@Kam471 thanks for the run. AI-assisted (Claude Code). |
Flyander
left a comment
There was a problem hiding this comment.
P2 — trailing JSON is accepted (tools/bvh_match.py:198)
I reproduced this on f57e6839 with the synthetic manifest {"Items":[{"Offset":1}]}junk: read_items() returns [{'Offset': 1}] instead of rejecting the invalid file. It returns as soon as it sees the closing } and never checks that the rest of the input is whitespace. The previous json.load() rejected extra data, so a truncated or concatenated manifest can now produce a plausible but incomplete match report.
After the closing brace, consume whitespace through EOF and raise ValueError if any non-whitespace remains. Please add a regression case for trailing garbage (and a second JSON value).
Review of ItsNotRexed#4310 (Flyander): read_items() returned as soon as it saw the closing brace, so `{"Items":[...]}junk` or a second JSON value after the object was accepted, while json.load refused both. Only whitespace may now follow the object; anything else is a ValueError ("extra data after the manifest object"), so main() prints one line and exits 2 as before. The test checks junk, a second object, a stray bracket and an empty object with junk, each also refused by json.loads, and that trailing whitespace and newlines are still fine. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@Flyander good catch, thanks. Fixed in 6b60bfe: after the closing brace only whitespace may follow; anything else is a
AI-assisted (Claude Code). |
Flyander
left a comment
There was a problem hiding this comment.
The updated stream reader now rejects non-whitespace after the closing object, and the tests cover junk, a second JSON value, and valid whitespace. The chunk-boundary scalar regression also exercises exponent forms and multiple chunk sizes. I rechecked both fixes and found no remaining actionable issue in this diff.
|
Tested 6b60bfe merged with main 1cc6e3c on Linux/Python 3.12.16: concern (conflicts with main, and the merged result regresses the bucket rule)
Negative control: with tools/bvh_match.py from main and the PR's tests, 76 errors (no read_items), so the streaming tests do test the new code. On main alone the suite is 40 of 40. Redundancy: not redundant; no merged PR streams the manifest (merged bvh_match PRs: #4559, #6330, #3935, #3787, #4497, #2712). |
Claimed in the coordination issue as: BUILD-1222 (claim; offered to @NiiRoZz, who had first refusal, here)
What and why
tools/bvh_match.pyloaded the wholerpf9dump modelsmanifest withjson.load. A fulllevels.rpfmanifest is 5.1 GB, and the process reached 20.6 GB of RAM.main()now calls a newread_items(), which:Itemsentry at a time (standard library only:json.JSONDecoder.raw_decodeon a sliding buffer);Offset,File,Name,MeshTris,MeshModels,MeshGeoms,MeshShaders, and each material'sShader, with the material list kept in place becauseMeshShadersindexes it;Count,Scan, ...);ValueErrorfor anything that isn't such an object (a top-level array, a truncated file, an item that isn't an object, a trailing comma), somain()still prints oneerror:line and exits 2.Nothing else in the matching changed:
model_geometries()gives the same rows for a slimmed item as for the full one.Tested
Windows 11 Pro 25H2 (build 26200), Python 3.12.10. CPU only, synthetic manifests; no GPU or game files.
python -I tests/test_bvh_match.py -v: 22/22 OK (18 existing + 4 new inTestStreamedManifest). The new tests run with a 7-byte chunk, so every token, number and item crosses a chunk boundary. They cover: slimmed items equal to a full load on the kept fields, extra fields dropped, members before and afterItems, a quoted and non-ASCII name, empty/missingItems, five broken inputs, andmain()reporting a truncated manifest in one line with exit 2.main'stools/bvh_match.pygiveFAILED (errors=3).tracemalloc:json.loadpeaks at 730 MB,read_itemsat 63 MB, in about the same time.python -m compileall -qon both files andgit diff --check: clean.AI-assisted (Claude Code).
Checklist
docs/design.md, with how it was confirmed. (N/A: no translator change.)🤖 Generated with Claude Code