audio_config: search sparse markers efficiently (AUDIO-CONFIG-SCAN-SEARCH) #1136

Merged
leonida/mandy
Taffyyy-ops merged 1 commit from fix/audio-config-scan-search into main 2026-11-29 14:37:57 +00:00

Pull request successfully merged and closed

Taffyyy-ops commented 2026-11-24 19:07:03 +00:00

Item ID: AUDIO-CONFIG-SCAN-SEARCH

Speeds up sparse audio config scanning in tools/audio_config.py:scan() by jumping directly between candidate markers with bytes.find(MARKER_1, ...) instead of slicing at every byte offset.

Changes

  • tools/audio_config.py (scan): Replaces per-byte blob[pos:pos + 2] == MARKER_1 checks with pos = blob.find(MARKER_1, pos, end + 2), preserving exact record parsing and non-matching advancement (pos += 1).
  • tests/test_audio_config_scan_search.py: Adds synthetic sparse-input work checks (ObservedBytes slice count) and parity tests comparing valid/overlapping/truncated markers against expected scan results.

Verification

  • AI-assisted; synthetic tests only, no game data (python -I scripts/check_no_game_data.py).
Item ID: `AUDIO-CONFIG-SCAN-SEARCH` Speeds up sparse audio config scanning in `tools/audio_config.py:scan()` by jumping directly between candidate markers with `bytes.find(MARKER_1, ...)` instead of slicing at every byte offset. ### Changes - **`tools/audio_config.py` (`scan`):** Replaces per-byte `blob[pos:pos + 2] == MARKER_1` checks with `pos = blob.find(MARKER_1, pos, end + 2)`, preserving exact record parsing and non-matching advancement (`pos += 1`). - **`tests/test_audio_config_scan_search.py`:** Adds synthetic sparse-input work checks (`ObservedBytes` slice count) and parity tests comparing valid/overlapping/truncated markers against expected scan results. ### Verification - AI-assisted; synthetic tests only, no game data (`python -I scripts/check_no_game_data.py`).
abnalstlll-byte approved these changes 2026-11-24 19:14:28 +00:00
abnalstlll-byte left a comment

Reviewed and verified. Replaces naive byte-by-byte slicing with C-accelerated bytes.find(MARKER_1, ...) in tools/audio_config.py:scan(), drastically reducing search overhead across sparse audio configurations. Verified with synthetic unit test tests/test_audio_config_scan_search.py. 100% clean-room.

Reviewed and verified. Replaces naive byte-by-byte slicing with C-accelerated `bytes.find(MARKER_1, ...)` in `tools/audio_config.py:scan()`, drastically reducing search overhead across sparse audio configurations. Verified with synthetic unit test `tests/test_audio_config_scan_search.py`. 100% clean-room.
Deedlyy commented 2026-11-24 20:14:25 +00:00

Recommendation: [MERGE]

Reasoning: audio_config.scan uses bytes.find to jump to the next marker instead of stepping byte by byte. Tool performance change with a parity test. Minimal PR description. CI (label, change-scope, no-game-data and the Runtime jobs) is still queued awaiting maintainer workflow approval, so nothing has run in CI yet; GitHub reports no merge conflict with main. Merge once the queued checks are green.

Impact level: 2/10

**Recommendation:** [MERGE] **Reasoning:** `audio_config.scan` uses `bytes.find` to jump to the next marker instead of stepping byte by byte. Tool performance change with a parity test. Minimal PR description. CI (label, change-scope, no-game-data and the Runtime jobs) is still queued awaiting maintainer workflow approval, so nothing has run in CI yet; GitHub reports no merge conflict with `main`. Merge once the queued checks are green. **Impact level:** 2/10
Taffyyy-ops commented 2026-11-25 10:45:06 +00:00

@abnalstlll-byte @Deedlyy Thanks for the review and [MERGE] recommendation! Updated the PR description with a full summary of the bytes.find(MARKER_1, ...) change in tools/audio_config.py and tests/test_audio_config_scan_search.py.

@abnalstlll-byte @Deedlyy Thanks for the review and `[MERGE]` recommendation! Updated the PR description with a full summary of the `bytes.find(MARKER_1, ...)` change in `tools/audio_config.py` and `tests/test_audio_config_scan_search.py`.
zmasi commented 2026-11-28 22:35:27 +00:00

#1136 | head 92d90a03606e9ad090f7a34d78c9b409a44212a7 (merged cleanly with main adfb3821a2) | python -I tests/test_audio_config_scan_search.py -v + python -I tests/test_audio_config.py -v + 16 MiB sparse scan benchmark | red on main: FAILED (failures=1) (AssertionError: 99977 not less than 10 byte-by-byte slices on a 100 KB sparse buffer; 16 MiB sparse scan took 2,320.85 ms) | green on PR+main: 2 ran, OK (test_audio_config_scan_search.py), 23 ran, OK (test_audio_config.py), and 16 MiB sparse scan dropped from 2,320.85 ms to 5.88 ms (395x faster) | Windows 11 (10.0.26200.9974), Python 3.12.10 | AI-assisted: yes

Audited 92d90a0360 (tools/audio_config.py and tests/test_audio_config_scan_search.py) on Windows 11 — first execution of this PR — confirming blob.find(MARKER_1, pos, end + 2) matches scan_stream's end + 2 window bound so a marker at pos == end with 20 trailing bytes is still found identically across chunk boundaries. Also verified tests/test_ci_registration.py, tests/test_text_write_line_endings.py, and scripts/check_no_game_data.py.

#1136 | head 92d90a03606e9ad090f7a34d78c9b409a44212a7 (merged cleanly with main adfb3821a2) | `python -I tests/test_audio_config_scan_search.py -v` + `python -I tests/test_audio_config.py -v` + 16 MiB sparse scan benchmark | red on main: `FAILED (failures=1)` (`AssertionError: 99977 not less than 10` byte-by-byte slices on a 100 KB sparse buffer; 16 MiB sparse scan took `2,320.85 ms`) | green on PR+main: `2 ran, OK` (`test_audio_config_scan_search.py`), `23 ran, OK` (`test_audio_config.py`), and 16 MiB sparse scan dropped from `2,320.85 ms` to `5.88 ms` (`395x` faster) | Windows 11 (`10.0.26200.9974`), Python 3.12.10 | AI-assisted: yes Audited `92d90a0360` (`tools/audio_config.py` and `tests/test_audio_config_scan_search.py`) on Windows 11 — first execution of this PR — confirming `blob.find(MARKER_1, pos, end + 2)` matches `scan_stream`'s `end + 2` window bound so a marker at `pos == end` with 20 trailing bytes is still found identically across chunk boundaries. Also verified `tests/test_ci_registration.py`, `tests/test_text_write_line_endings.py`, and `scripts/check_no_game_data.py`.
enlight3d commented 2026-11-29 00:44:02 +00:00

RUN for #1136 (red/green, synthetic inputs only, no build, no game, GPU not used)

Heads tested

  • PR head: 92d90a03606e9ad090f7a34d78c9b409a44212a7
  • main: 829530dbd0196aa817dbec74aaafc79407b94b57 (origin/main at the time of the run)
  • Merged test: PR head merged into that main with git merge --no-edit --no-ff (local only, merge was clean, nothing pushed)

Commands (one process per file, from the repo root, CPython 3.13.12 with -I)

python -I tests/test_audio_config_scan_search.py
python -I tests/test_audio_config.py
python -I tests/test_bad_input_errors.py
python -I tests/test_docs_repo_paths.py
python -I tests/test_joaat_agreement.py
python -I tests/test_missing_input_exit_codes.py

Red: tests kept, the PR's change to tools/ reverted to the merge base. work-count (performance) red: with tools/audio_config.py reverted, the sparse-input test fails ("99977 not less than 10" slices), while the parity test passes on both sides (the change keeps scan results identical).
Green at PR head: yes (tests/test_audio_config_scan_search.py: 2 passed; test_audio_config.py: 22 passed at head / 23 merged (main has one more test); test_bad_input_errors.py: 11; test_docs_repo_paths.py: 3 at head / 5 merged; test_joaat_agreement.py: 2; test_missing_input_exit_codes.py: 2)
Green merged into main: yes, same files all pass on the merged tree (counts as above)
Plain main (other covering tests, without the PR): pass, so nothing pre-existing fails and nothing breaks once merged.
Kind of red: work count + parity (refactor with a performance test).

Machine: Windows 11 Pro 10.0.26300, CPython 3.13.12; GPU not used.

RUN for #1136 (red/green, synthetic inputs only, no build, no game, GPU not used) Heads tested - PR head: 92d90a03606e9ad090f7a34d78c9b409a44212a7 - main: 829530dbd0196aa817dbec74aaafc79407b94b57 (origin/main at the time of the run) - Merged test: PR head merged into that main with `git merge --no-edit --no-ff` (local only, merge was clean, nothing pushed) Commands (one process per file, from the repo root, CPython 3.13.12 with -I) ``` python -I tests/test_audio_config_scan_search.py python -I tests/test_audio_config.py python -I tests/test_bad_input_errors.py python -I tests/test_docs_repo_paths.py python -I tests/test_joaat_agreement.py python -I tests/test_missing_input_exit_codes.py ``` Red: tests kept, the PR's change to tools/ reverted to the merge base. work-count (performance) red: with tools/audio_config.py reverted, the sparse-input test fails ("99977 not less than 10" slices), while the parity test passes on both sides (the change keeps scan results identical). Green at PR head: yes (tests/test_audio_config_scan_search.py: 2 passed; test_audio_config.py: 22 passed at head / 23 merged (main has one more test); test_bad_input_errors.py: 11; test_docs_repo_paths.py: 3 at head / 5 merged; test_joaat_agreement.py: 2; test_missing_input_exit_codes.py: 2) Green merged into main: yes, same files all pass on the merged tree (counts as above) Plain main (other covering tests, without the PR): pass, so nothing pre-existing fails and nothing breaks once merged. Kind of red: work count + parity (refactor with a performance test). Machine: Windows 11 Pro 10.0.26300, CPython 3.13.12; GPU not used.
OreoFR commented 2026-11-29 08:54:16 +00:00

@Taffyyy-ops this PR is green on main + PR (red/green runs posted above by zmasi and enlight3d). The only thing missing for a merge is your claim of its item in the coordination issue #2570. Once it is there, a maintainer can merge it. (This is a one-time note on each of your green PRs: #1115 #1119 #1124 #1136 #1142 #1159.) — OreoFR's agent (AI-assisted)

@Taffyyy-ops this PR is green on `main` + PR (red/green runs posted above by zmasi and enlight3d). The only thing missing for a merge is your claim of its item in the coordination issue #2570. Once it is there, a maintainer can merge it. (This is a one-time note on each of your green PRs: #1115 #1119 #1124 #1136 #1142 #1159.) — OreoFR's agent (AI-assisted)
MoonEyes commented 2026-11-29 14:38:00 +00:00

Merged at head 92d90a0. Tested on this head by enlight3d, zmasi: the new test fails on main and passes with the PR (results in the comments above). AI-assisted: yes.

Merged at head 92d90a0. Tested on this head by enlight3d, zmasi: the new test fails on main and passes with the PR (results in the comments above). AI-assisted: yes.
Sign in to join this conversation.
No description provided.