Skip to content

rdna2_decode: stream the text listing instead of retaining every instruction - #4963

Open
tupacfan04 wants to merge 1 commit into
ItsNotRexed:mainfrom
tupacfan04:fix/rdna2-decode-stream-text
Open

tupacfan04 wants to merge 1 commit into
ItsNotRexed:mainfrom
tupacfan04:fix/rdna2-decode-stream-text

Conversation

@tupacfan04

@tupacfan04 tupacfan04 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as #4932 (claim).

What and why

rdna2_decode.disasm_bytes() called decode_bytes(), kept every decoded instruction dictionary, built a second list of formatted lines, and joined it. For a text-only caller that doubled the retained Python objects until the final string existed.

  • Added _iter_decoded(), which yields each instruction (or None for an invalid word) as soon as it is decoded.
  • decode_bytes() keeps collecting the structured result its callers expect.
  • disasm_bytes() formats each instruction and writes it to a StringIO immediately, so the instruction dict and its formatted line are released before the next decode.
  • Output, code_start handling, the trailing newline and the invalid-word count are unchanged.

Measured on Windows 11 with CPython 3.14.7, using bytes.fromhex("000040d501050e04") * 8192 + b"\xff" and tracemalloc started immediately before the call:

Peak traced Python allocations
Before 11.67 MiB
After 1.86 MiB

Both return the same 778,240-character listing and report one invalid word. This measures Python allocations only, not RSS or throughput.

Tested

  • py -3 -I -m pytest tests/test_rdna2_decode.py tests/test_rdna2spirv_decode.py tests/test_shader_disasm.py -q: 57 passed, 1 skipped, 72 subtests passed.
  • py -3 -m compileall -q tools/rdna2_decode.py: exit 0.
  • Byte-identical output against the old path on seven cases (empty input, one instruction, two instructions, trailing invalid byte, non-zero code_start, wave32=False, and the 2,048-instruction repeated input), compared by SHA-256 of the full listing plus the invalid count.
  • No GPU, no game data and no external tools are involved.

AI-assisted: the change, tests and this description were written by an AI coding agent running in OpenCode and checked by the commands above.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (Not a translator change.)

Depends on: nothing.

@tupacfan04
tupacfan04 force-pushed the fix/rdna2-decode-stream-text branch 2 times, most recently from 7786790 to 595c5dc Compare November 23, 2026 06:57
@tupacfan04
tupacfan04 force-pushed the fix/rdna2-decode-stream-text branch from 595c5dc to e54f1cf Compare November 23, 2026 07:00
@Atomic258

Copy link
Copy Markdown

Independent check of e54f1cf1 — pass.

Environment: Windows 11, CPython 3.15.2, CPU only. Synthetic inputs, no GPU, no game files.

  • python -I tests/test_rdna2_decode.py → 14 tests, 13 pass / 1 skip (platform-gated)
  • Negative control: PR tests against main's tools/rdna2_decode.py → 2 failures (disasm_bytes used decode_bytes — the streaming path isn't taken on the old code), so the new tests pin the change
  • compileall clean, git diff --check main...HEAD clean

Read the diff: text listing now streams per-instruction instead of accumulating — the memory win the title claims, with the byte path preserved for the binary listing. No issues found.

AI-assisted (Devin).

@SphyserX

Copy link
Copy Markdown

Tested e54f1cf on Arch Linux (in a VM), CPython 3.14, LLVM 23.1.5: pass.

@kapitche

Copy link
Copy Markdown
Contributor

Tested e54f1cf merged with main 3faac55 on Linux (WSL2), CPython 3.12.16, CPU only: pass

  • python -I tests/test_rdna2_decode.py: 14 run, 13 passed, 0 failed, 1 skipped (llvm-mc parity test, llvm-mc not installed here).
  • Negative control: tools/rdna2_decode.py restored from main, same test file: 14 run, 2 failures (disasm_bytes used decode_bytes), so the streaming tests do fail without the change.
  • Read the diff: decode_bytes and disasm_bytes now share _iter_decoded, the invalid-word step (max(4, nbytes)) is unchanged, and the empty-input and invalid-word cases are covered by the new tests. No issue found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants