Repository navigation
Conversation
…faster, same values parse_scalar tests the common token shapes without a regex call and matches the rest with one combined pattern; parse_content converts an array body of plain decimal numbers with float()/int() in one pass and groups with zip; Reader.convert returns <x value=".."/> and plain vectors before the full ladder, skips with_attributes when every attribute is one a convention consumes, and assemble classifies children in one loop. No cache and no global state. tests/test_gamedata_reader_fast_paths.py compares the values, statistics, types and errors with an inline reference implementation on known tokens, random tokens, random array bodies and random generated documents. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Confirmed a behavior change at 45ba98a when a registered type handler replaces the element’s attribute dictionary. With a synthetic element.attrib = {**element.attrib, "units": "meters"}
return 7The base reader returned
AI-assisted source review and synthetic test. |
|
Independent check of 45ba98a on Windows 11 / Python 3.15.0: pass.
No game files or GPU involved. AI-assisted verification (Codex). |
|
Retail check at Summed thread CPU time inside |
|
Tested What passes
Blocking finding
Refreshing AI-assisted. |
|
Thanks @hcampbell98 and @CourtyardGames for catching that! Fixed in 4da8991 by refreshing |
|
Tested head 45ba98a vs main dde82f2 (merged tree 746ac6856, clean): new suite Ran 10 OK; the gamedata family Ran 177 with one failure — test_gamedata_blobs BadCarveIndexTest.test_missing_file_names_what_is_wrong — which fails identically on clean main (main-side regression from #6701's error-convention flip), not attributable to you. Since your suite compares against an inline reference, I ran an independent differential between main's and your gamedata_reader: 1,541 crafted tokens, 12,160 kind×body combos, 3,000 random documents — 0 mismatches in values, types, exceptions and stats. Mutation probes on the three fast branches turn the suite red (41/31/101 failures), md5-clean restore. Measured: array bodies 2.9-3.7x, int scalars ~1.5x — but float scalars 0.84x and hex scalars 0.63x; the title range holds for array/mixed workloads, so a one-word scope note on the title would be accurate. Checks pending. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run). |
AI-assisted (Claude Code, Claude Sonnet 5.5). Claimed in the coordination issue (#7599) as a new PERF item.
What
tools/gamedata_reader.pyconversion hot paths, with no change to values, statistics (elements by convention),typesor errors:parse_scalar:isdecimal()replaces the INT regex call, and one combinedSCALARpattern (int, hex, float; ignore-case kept on the float part only) replaces up to threefullmatchcalls.parse_content: a body whose characters are only0-9 . + -and ASCII whitespace converts withfloat()/int()in one pass (all tokens dotted, or none dotted; any ValueError, for example1.2.3, falls back to the token-by-token path); vector/matrix grouping useszip.Reader.convert: returns<x value=".."/>and plain<v x y z w/>elements before the full ladder, and skipswith_attributeswhen every attribute is one a convention consumes.assembleclassifies children in one loop instead of up to twoall()passes.Not touched:
read,run,documents, the docstring header,tools/gamedata_sps1.py,tools/gamedata_xml.py,tools/rbf0_tree.py. Open PRs touching this file (#7512, #6568, #3856, #4291) change other lines.Benchmarks (synthetic documents generated by hand, no game data; Windows 11, Python 3.12.10, min of 40 interleaved
Reader().readruns, before =origin/main6664b0d)0x2,2.5f, ints) that take the fallback path (0.54 MB)A second full run of the same script gave mixed -37.1%, arrays only -60.6%, scalars/vectors -43.2% and sparse/odd -21.6%, so the sparse/odd stress case (nearly every token on the fallback path) sits around 22-26% while the three realistic shapes stay at 33-65%. The machine is noisy: repeated runs of the same comparison varied by about +-8 points (the sparse row went from 22% to 26% between runs), and the others stayed above 33%. For scale,
ET.iterparsealone takes about 78 ms of the mixed document and is unchanged.Memory (
tracemallocpeak of oneReader().read)An earlier draft that validated a whole array body with one repeated regex peaked at 29 MB against 5.4 MB for a 60k-float body (the regex engine keeps state per repeated token); the unit test below caught it and it was replaced by the character-set check used here.
Tests
New
tests/test_gamedata_reader_fast_paths.py(standard library, platform-independent: every expectation is computed by a reference implementation inside the test, no hashes or byte pins):parse_scalaragainst the reference on known edge tokens (hex case,1.5f,inf/nan,1_0, Arabic-Indic digits, NBSP, empty), 60,000 random tokens and 20,000 random numbers; value, type (1vs1.0vsTrue), signed zero, NaN and error message all compared.parse_contenton every array kind against bodies that take the bulk paths and their near misses (non-ASCII whitespace and digits,1..5,1.5 2, odd counts) plus 40,000 random bodies.Reader.readagainst a referenceReadersubclass without the shortcuts on 500 generated documents (with and without type handlers) and the vector-shortcut edge cases: values,statsandtypesequal.Two deliberate bugs (skipping the float check in the vector shortcut; widening the no-extras shortcut) each fail three of these tests.
Run on Windows 11, Python 3.12.10, no GPU involved:
python -m compileall -q tools/gamedata_reader.py testspython -I tests/test_gamedata_reader.py(22 tests, OK)python -I tests/test_gamedata_reader_fast_paths.py(10 tests, OK)tests/semanticwas not run (the translator is not touched).🤖 Generated with Claude Code