Skip to content

perf(testing): cut cant-fail-scan's process starts by a third, about 25% off on Windows - #13408

Merged
kyle-sexton merged 5 commits into
mainfrom
ccp-13231-spawn-cut
Nov 5, 2026
Merged

kyle-sexton merged 5 commits into
mainfrom
ccp-13231-spawn-cut

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

Closes #13231

Summary

cant-fail-scan.test.sh was the slowest suite on Windows Git Bash. Lane 5's one-walk cut showed no Windows gain (#13231), so this change starts from where the process starts go. A Linux strace -f of one engine leg, attributed by nearest parent and weighted by Lane 5's Windows per-launch costs, gave these estimates:

Bucket Starts Est. Windows s
scanner sort 4,999 165
harness (the suite itself) 6,769 137
scanner pure subshells 12,700 127
find 3,743 82
tr 2,152 78
xargs 1,249 67
mktemp 1,377 61

The estimate totals 953 s against about 780 s measured. It runs high because pipeline stages and parallel engine jobs overlap. Lane 5's over-prediction came from the mawk leg: Linux runs the suite twice (gawk, then mawk), and Git Bash has no mawk (cant-fail-scan.test.sh:2427).

Fix

  • Scanner (cant-fail-scan.sh):
    • One mktemp -d replaces the separate temp files.
    • The walks that feed xargs use -print0 with no sort or tr stage, since their output is sorted afterwards. The test-file walk's double sort is gone.
    • tr -d '\r' is now parameter expansion. A dir_of helper matches dirname, and basename is parameter expansion.
    • pick_adapter sets a variable instead of running in a subshell. nproc runs only when the scan can go parallel. The error-line count is a read loop, not awk.
    • The number of walks is unchanged, so Lane 5's cut is not repeated.
  • Harness (cant-fail-scan.test.sh): the corpus loop runs once per fixture (326 of them), one tagged sed pass reads their headers, and set_of builds the rule sets in bash. No assertion changed.
  • docs/test-wall-clock-baseline.md: the suite's row has the new Windows time.

Verification

  • Byte-identical output:
    • old and new scanners match across 1,780 pin files: the repository tree, every fixture directory and corpus file, all modes, serial and parallel, gawk and mawk;
    • they also match across 252 hook-mode runs (--lines, --brief, --inventory);
    • the suite prints the same PASS lines before and after.
  • Process starts, one leg: 43,922 before, 30,377 after.
  • Linux, three alternated pairs (s), all passed: before 105.8, 107.7, 108.0; after 77.0, 81.8, 80.6.
  • Windows Git Bash, this desk via WSL interop, two alternated pairs (s), all passed, WSL load at most 3.15: before 1294, 1421; after 993, 1069. The pairs don't overlap: about 25% faster. Both sides ran higher than Lane 5's 780 s on the laptop, since this is a different host. The "before" tree was the branch base, b70be89.
  • Not this change: test-scan.test.sh and test-weaken.test.sh each fail one case locally, the same way on the base clone. That's this host's mise output leaking under a temporary HOME. CI doesn't use mise.

Related

🤖 Generated with Claude Code

kyle-sexton and others added 5 commits November 4, 2026 17:04
The audit suite runs the scanner 643 times, and each run started about 55
processes before reading a file. On Windows Git Bash a start costs 10 to 54 ms,
so that fixed cost dominated the suite's wall clock there.

- One mktemp -d holds the walk-error log, adapter table, extend list and the
  parallel engine's records, in place of two to four mktemp calls.
- The walk feeding xargs prints NUL-separated and unsorted: its callers sort
  grep's output, so the sort and tr stages did nothing.
- The test-file walk merged with content claims is no longer sorted twice.
- git output drops carriage returns by parameter expansion, not tr.
- dirname and basename become parameter expansion (dir_of keeps dirname's
  answer for every path shape), pick_adapter sets a variable instead of
  printing into a subshell, nproc runs only when a parallel scan can happen,
  and the error-line count is a read loop instead of awk.

Output is byte-identical to the previous scanner over the repository tree,
every fixture directory and every corpus file, in report, --count, --check,
--check --strict, --blocks and --findings modes, serial and parallel, under
gawk and mawk.

Refs: #13231

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…test.sh

The corpus loop runs once per corpus fixture (326) and started about 13
processes per fixture around the scanner call: three seds for the reads,
adapter and expect headers, a grep for exempt, and two sed | sort -u | paste
pipelines for the expected and reported rule sets. One tagged sed pass now
reads all four headers, and set_of builds both rule sets in bash.

The assertions and their labels are unchanged: the extracted values match the
old pipelines on all 326 fixtures, and the suite prints the same PASS lines.

Refs: #13231

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… spawn cut

Alternated Windows Git Bash pairs on one host: 1294 and 1421 s before, 993 and
1069 s after; every run passed.

Refs: #13231

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	docs/test-wall-clock-baseline.md
@kyle-sexton
kyle-sexton marked this pull request as ready for review November 5, 2026 01:13
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-05T01:26:13.629415Z aab588c Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

claude-security-review reviewed aab588cbed7193c8cdb80c074827d9ee4bf0fbe9: read 4 of 4 changed file(s); 0 finding(s), 0 as inline comments.

Security review: PR #13408 (full review, first head)

I found no security issues in this change.

I read every hunk of all 4 changed files. None of them matches a trusted-path glob, and none is a trust control, merge hold, plugin manifest or standing instruction.

What I checked:

  • Temp files in cant-fail-scan.sh. The script now makes one directory with mktemp -d instead of several mktemp files. If mktemp -d fails, the script exits with an error instead of scanning. The EXIT trap is rm -rf "${SCRATCH:?}", and the :? guard means an empty variable cannot turn it into a bare rm -rf. The fixed file names inside that private directory (walk-errors, adapters, extend) are not predictable shared paths. The parallel engine's numbered records ($i, $i.part, $i.err at lines 988-999) cannot collide with those names. This is no worse than before, and arguably safer.
  • EXTEND_FILE. It now always points at $SCRATCH/extend and is only ever appended to. No outside input picks the path.
  • The find/xargs switch to -print0. It removes the tr '\n' '\0' stage. NUL-separated names are at least as safe as newline-separated ones (a filename containing a newline no longer splits), and grep still gets -- before the file list.
  • dir_of, ${FILE##*/} and the \r stripping by parameter expansion. These work only on strings and run no commands. The cd "$DIR_OF" calls quote their argument.
  • The read loop that replaces awk for the walk-error count. It reads a file inside the private directory.
  • Test harness (cant-fail-scan.test.sh). The tagged sed pass and the set_of helper replace sed | sort -u | paste in the suite. The suite's own fixtures are the only input. No privilege boundary is involved.
  • Changelog entry and docs/test-wall-clock-baseline.md. Prose only.

PR context: it contains no embedded instructions aimed at the review lane.

Spend: the PR does not change spending. It only makes a local test suite run faster.

critical-findings: 0

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

claude-review reviewed aab588cbed7193c8cdb80c074827d9ee4bf0fbe9: read 4 of 4 changed file(s); 0 finding(s), 0 as inline comments.

Code review: no findings

I read every hunk in all 4 changed files: the changelog fragment, docs/test-wall-clock-baseline.md, cant-fail-scan.sh and cant-fail-scan.test.sh. I also read the surrounding scanner code at head. None of the changed files is on a trusted path.

What I checked (by reading the code; I ran nothing)

dir_of against dirname. I traced these inputs: "" gives ., / and /// give /, a and a/ give ., /a gives /, a/b and a//b give a. Each matches GNU dirname. The only difference is //a, which gives / where GNU gives //; cd lands in the same place, so nothing changes. The inner expansion ${p%"${p##*[!/]}"} is quoted, so glob characters in a path are taken literally.

Scratch directory. The parallel engine's files are $i, $i.part and $i.err, so they can't collide with walk-errors, adapters or extend. Nothing globs the directory.

  • ADAPTER_TABLE is written by > before it is read (lines 456 and 483).
  • WALK_ERR is created up front with : >, so the new done <"$WALK_ERR" loop always has a file to read.
  • The trap uses ${SCRATCH:?}, which guards against rm -rf on an empty path.
  • If mktemp -d fails, the script now stops with exit 2. Before, it fell back to a serial run. That is a reasonable tightening.

pick_adapter/PICKED. Every return path sets PICKED, so no value from the previous file can leak into the next one.

collect_files -print/-print0. Every unsorted caller sorts afterwards: the union walk is piped through | sort, and so is the retryTimes walk. content_files only feeds that sorted union. The other callers (lines 688, 706 and 709) still get sorted output. -print0 also fixes the old tr '\n' '\0' approach for filenames with spaces.

max_jobs. It is only read in the parallel gate, so skipping nproc for --file and single-file scans changes nothing else.

Walk-error count. The read loop counts lines that contain something other than a space or tab, including a last line with no newline. That matches awk's NF with the default field separator.

\r removal. read at end of input leaves the variables empty rather than unset, so ${TOP//$'\r'/} is safe under set -u.

Test harness.

  • The tagged sed pass (h/g around each s///p) yields the same reads, adapter, expect and exempt values as the old separate commands. The old code read $copy, which is a byte copy of $CORPUS/$rel, so reading the original is equivalent.
  • The BASH_REMATCH regex matches the old sed pattern.
  • set_of builds both want and got, so the two sides are always ordered the same way.
  • Assertion texts are unchanged.

Closing issue #13231, Done when

  • The Linux before and after times are in the PR body. Met (author-claimed, unverified).
  • The re-measured Windows time is in the PR body and in the suite's row of the baseline doc (now 1069, with a prose note giving both pairs). Met in the diff; the timings themselves are author-claimed and unverified.
  • The suite's assertions are unchanged, and the harness edit is named in the PR body. Met.
  • ci-status is green on the PR head. I can't check this from this lane.

The claims of byte-identical output and of the process-start counts are the author's own and unverified.

No plugin manifest changed. The changelog fragment's bump: patch fits a behavior-preserving performance change.

@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 5, 2026
Merged via the queue into main with commit d87bc9e Nov 5, 2026
70 checks passed
@kyle-sexton
kyle-sexton deleted the ccp-13231-spawn-cut branch November 5, 2026 01:52
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Post-merge mutation testing

Killed 3, survived 4, timeout 0, no coverage 0, invalid 0, not run 0.
Covered-code score 43%; mutation score 43%.

File Killed Survived Timeout No coverage Invalid Not run
plugins/testing/skills/audit/scripts/cant-fail-scan.sh 3 4 0 0 0 0

Surviving mutants

Location Operator Disposition Cause
plugins/testing/skills/audit/scripts/cant-fail-scan.sh:271 other productive input-gap
plugins/testing/skills/audit/scripts/cant-fail-scan.sh:280 SBR productive input-gap
plugins/testing/skills/audit/scripts/cant-fail-scan.sh:1135 ROR productive input-gap
plugins/testing/skills/audit/scripts/cant-fail-scan.sh:982 LCR unclassified none

The run's summary has the full report.

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.

perf(test): cut cant-fail-scan.test.sh's Windows wall clock (891 s against 128 s on Linux)

1 participant