Skip to content

test_mutations: run its 14 semantic runs together on hard-linked tools copies (Windows 293 s -> 97 s) - #4827

Open
kapitche wants to merge 1 commit into
ItsNotRexed:mainfrom
kapitche:kap-mutfast
Open

kapitche wants to merge 1 commit into
ItsNotRexed:mainfrom
kapitche:kap-mutfast

Conversation

@kapitche

Copy link
Copy Markdown
Contributor

Item: new TEST item, claimed here. Depends on: none. Touches only tests/semantic/test_mutations.py; no overlap with #4513/#4514/#4626, and #3883 (closed) is not needed, the anchor on main is already current.

What was slow. test_mutations makes 14 independent runs (a baseline plus 13 mutations), each a fresh interpreter that copies tools/ and recompiles the 16k-line rdna2spirv.py. Profile (python -I -m cProfile): on Windows 3.13.1 one compile() of the translator is 7.7 s, on Linux 3.12.16 it is 0.5-1.8 s (loaded machine); the 6 MB copy is only 0.16 s on Windows. So the 9x gap is compile speed times 14 sequential runs, not the copy or process spawn.

Fix. The 14 runs are independent, so setUpClass starts them together on a thread pool (subprocesses, so no GIL issue) and the tests read the results. tools/ copies now hard-link every file except the mutated one (copied, so the repository file is never touched). Same mutations, same anchors, same expected failing test per mutation; no assertion changed.

Measured. Windows 3.13.1, unittest discover -p test_mutations.py, machine shared with other jobs: 293 s -> 97 s. Linux 3.12.16 (also loaded): 54 s -> 28 s. The CPU total is unchanged (14 compiles), so under #4357's parallel runner the gain is wall time when cores are free.

Equivalence. Per mutation, the sequential (main) and parallel paths give the same result: all 13 return rc 1 with exactly the expected test_ps_* failing; baseline passes. Negative control: a no-op mutation (anchor replaced by itself) returns rc 0 and is reported as not detected, so a surviving mutation is still surfaced. git status in the repo after the runs shows tools/ untouched. Tested on Windows 3.13.1 and Linux 3.12.16.

AI-assisted.

@Atomic258

Copy link
Copy Markdown
Contributor

Tested 5a3e4016 on Windows 11, CPython 3.15.2, CPU only (no GPU, no game files): pass.

Command: python -I -m unittest discover -s tests/semantic -p test_mutations.py -v

Result: 3 tests, all OK in 5.1 s (test_anchors_match_crlf_translator_copies, test_baseline_copy_passes, test_each_mutation_is_caught).

Red control: the file under test is itself the harness, so the built-in negative controls serve: all 13 mutations were applied to hard-linked copies of tools/ and each was caught (non-zero rc with the expected test_ps_* failure), and the baseline copy passed. git status --porcelain is clean after the run, confirming the repository tools/ was never touched.

AI-assisted (Devin); no game files.

@tupacfan04

Copy link
Copy Markdown
Contributor

ACCEPT. The 3 tests pass and the measured runtime is 118 s versus 274 s on main (~2.3x; the body's 97/293 is optimistic). The sharing is real (197/202 inodes shared), and the Windows os.link fallback to copy2 was verified by simulating OSError without admin. A no-op mutation still returns 0 and is reported as not detected, so the control is intact.

Two issues worth tightening:

  • tests/semantic/test_mutations.py:122 keys the link/skip decision on the basename, so a future fname containing a directory could still hard-link and write through into the repo. That is latent today.
  • The "repository tools never modified" guarantee (:4-6, :114-116) now holds only for the mutated file; a run that writes into the tools directory could hit the shared inodes.

Approve. AI-assisted review, no game files, no GPU.

@kapitche

Copy link
Copy Markdown
Contributor Author

Full tests/semantic run, per-test outcomes, on upstream/main (a), main + #4828 (b), main + #4827 (c), main + both (d). Runner: #4357's scripts/run_semantic_tests.py (copied into scratch worktrees, not committed), unmodified, with a thin wrapper that loads each file with a result class printing <test id> <outcome>, so the comparison is per test (396 files, 6247 test/subtest results each).

platform variant ok skip xfail fail/error per-test diff vs (a) runner wall time
Linux, Python 3.12.16, -j 14 a main 6224 16 1 6 - 143 s
b #4828 6224 16 1 6 0 189 s
c #4827 6224 16 1 6 0 188 s
d both 6224 16 1 6 0 167 s
Windows 11 native, Python 3.13.1, -j 14 (a) / -j 9 (b, c, d) a main 6224 16 1 6 - 573 s
b #4828 6224 16 1 6 0 516 s
c #4827 6224 16 1 6 0 479 s
d both 6224 16 1 6 0 356 s

@memorypressure

Copy link
Copy Markdown

Verified on Linux (CPU-only): merges cleanly with current main 3faac55, compileall clean, and tests/semantic/test_mutations.py passes under python -I (re-run) — baseline and all 14 mutations detected, CRLF anchor included. test_ps_semantics and the translator-use guard also pass on the merged tree; nothing on main touched this file since your base. The parallelization is sound: mutated files are real copies, the rest hard-linked, bytecode writing disabled — only the mutated file is ever written. One nit: each semantic run completes in well under a second here, so the comments a second or more estimate is generous. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@Atomic258

Copy link
Copy Markdown
Contributor

Tested 5a3e401 on Windows Server 2022, CPython 3.13.12: pass

  • python -I -m unittest discover -s tests/semantic -p "test_mutations.py" -> OK

git diff --check clean; python -m compileall -q exit 0. No game files, no GPU. AI-assisted (Devin).

@kapitche

Copy link
Copy Markdown
Contributor Author

Thanks for the check. On the "a second or more" estimate: I timed python -I -m unittest discover -s tests/semantic -p test_mutations.py three times on this machine (Linux/WSL2, Python 3.12.16, loaded host) at 17.6 s, 22.1 s and 12.2 s wall, with 43.8 s, 42.8 s and 28.2 s of user CPU across the 15 child interpreters. That is about 2-3 s of CPU per run here, so "a second or more" holds as a lower bound on this box; a faster CPU than this one will see less. I left the comment as is, since it only describes the cost and no code depends on it.

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