Repository navigation
rsc8_audio: optional native header and table kernels (tools/audio_native), 43x-140x per table, Python fallback (PERF-RSC8-AUDIO-NATIVE) - #8947
Open
TG0000 wants to merge 2 commits into
Conversation
…ive), Python fallback (PERF-RSC8-AUDIO-NATIVE) A zero-dependency Rust cdylib for the word loops of parse_adat_header_bytes, decode_grid20_table, decode_index_runs, decode_marker_records and the region-cue check before pair_marker_regions, loaded with ctypes by tools/_audio_native.py. The Python code stays the reference and runs when the library is missing, fails to load, reports another ABI, declines a call, the table is below the call-overhead threshold, or LEONIDA_AUDIO_NATIVE=0. tests/test_audio_native.py: 1,500 seeded synthetic cases per kernel (valid and broken), edges at every threshold and word bound, whole banks through decode_awc_bank, fallback cases, and optional timings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ic GC A library call must not switch off the collector for the whole process (another thread may be allocating). The entries are still unpacked with struct.iter_unpack and islice; parse_adat_header_bytes is now ~2x faster than the reference on a 50,000-stream header instead of ~5x. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Tested head a7af291 on Linux x86-64 (WSL2), CPython 3.14.10, cargo 1.100.0. CPU only, synthetic data only, no game files. Result: no defect found. What ran:
The kernels answered 407,218 header, 128,139 grid, 238,287 index-run, 152,493 marker and 202,844 region-value calls. The rest were below the Not tested: Windows or macOS, real AWC banks, the PR's timing numbers, and the CI step itself. Review written by Claude (Claude Code, Opus 5.5), an AI agent, posted from a contributor's account. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Item: PERF-RSC8-AUDIO-NATIVE (claimed in #8868). AI-assisted (Claude Code): an agent wrote and checked it on CPU only, using synthetic data only.
What changed
tools/rsc8_audio.pyhas no PCM or ADPCM code. Its per-word Python loops are the AWC (ADAT) header parse and the companion-table decoders, which run for every stream of a scan. This adds an optional Rustcdylibfor those loops:tools/audio_native/(no dependencies,[dependencies]empty,panic = "abort"):audio_adat_header_v1,audio_grid20_v1,audio_index_runs_v1,audio_markers_v1,audio_marker_has_value_v1, plusaudio_native_abi().tools/_audio_native.py: thectypesadapter. Every function returnsNoneto fall back.tools/rsc8_audio.py(+43/-2): one fast-path call in each ofparse_adat_header_bytes,decode_grid20_table,decode_index_runsanddecode_marker_records, placed after the reference's own size checks. In_tally_undocumented_tables, the start/end cue check runs beforemarker_records(), so a tag with no region cue no longer builds its record list. The Python code is unchanged and stays the specification.The reference runs when:
bytes;MIN_*size, where the ~1 µsctypescall costs about as much as the Python loop;LEONIDA_AUDIO_NATIVE=0is set.Numbers
Python 3.12.10, Windows 11, one core, synthetic inputs. Best of 3 runs (Python) and best of 7 (native), same process, results compared with
repr; ranges are over three separate runs:decode_grid20_table, 100,000 entriesdecode_index_runs, 1,000 groups x 100decode_marker_records, 100,000 recordsparse_adat_header_bytes, 50,000 streams x 3 tagsdecode_awc_bankx6 banks (40 streams each, 150-4000x5aentries, 20-600xd9groups, 200-6000xbdrecords, a clip on every 4th stream)struct.iter_unpackandislice. It does not touch the cyclic GC (a library call must not pause it for other threads), and the collector runs during that build in both paths, which is most of what is left.docs/rsc8_audio.mdcounts 781,350 records in 420,1680xbdtags, which is about 2 records per tag. Those tags stay belowMIN_MARKER_BYTESand run in Python. The large0x5a/0xd9tables and big headers are where the kernels pay off.Parity
tests/test_audio_native.pycompares each fast path against the reference withrepr, so key order,Noneandboolmust match too, as must the first-seen order of thenamesdict:count/hdr_sz, truncation, a bad magic, a zero-stream bank whose tables do not fill the header, a non-zerobank_offset;p, a bad magic, truncation;MAX_INDEXRUN_GROUPScap (patched down to 5);MIN_*threshold,0xFFFFFFFFwords, andbank_offset/file_sizeat 2^63, at 2^64 (declined), and negative (declined).decode_awc_bank, with identical JSON with and without the kernels.CDLLthat raises, a library with another ABI, declined inputs, and every kernel returning its decline code. Each of these still gives the reference result.Tests run
cargo build --release --lockedandcargo test --release --lockedintools/audio_native: no warnings; 5 tests pass.python -m compileall -q make_game.py tools testsandpython -I make_game.py --help: pass.python -I tests/test_audio_native.py(14 tests, withLEONIDA_AUDIO_NATIVE_BENCH=1): pass. WithLEONIDA_AUDIO_NATIVE=0the 11 native-only tests skip and the rest pass.python -I tests/test_rsc8_audio.py(49 tests) with and without the library: pass.test_awc_markers.py,test_awc_cue_labels.py,test_awc_manifest.pyandtest_audio_wav.py: pass, with skips where game files are needed.scripts/check_no_game_data.pyon the new and changed files: clean.test_text_write_line_endings.pyfails ontools/leonida_tui.py:753andtools/wave_diff.py:373, the same as on main. Neither file is touched here.checkjob builds and tests the crate offline (like the BCPack step), asserts that the library loads, and runs both test files.No GPU or driver is involved, and
tests/semanticwas not run because nothing in the translator changed.Overlap
#7266 (TG0000, pure Python) rewrites the bodies of the same four decoders, so a trial merge conflicts in those functions. Whichever lands first, the other gets a rebase: the fast-path calls sit right after each function's size checks, so they port to either version of the loops. None of the other open
rsc8_audioPRs touches these functions.Depends on: none.
🤖 Generated with Claude Code