scripts: Check formatting in parallel
6585c8e324fb1525ed5255c6fb2b77be7ce08443358afe3e7cde796ab4db9bd5
check-fmt started one emulator per file in a serial loop, so checking the whole tree took 2.9 s, almost all of it spent on the 176 separate runs. It now runs the checks with xargs on as many jobs as there are CPUs, and takes about 0.5 s on 24 CPUs. The exit status and the reported files are unchanged, but the order of the reports is not fixed any more. Assisted-by: Claude:opus-5.5
1 parent
f1ee027f
scripts/check-fmt
+12 -11
| 51 | 51 | *) |
|
| 52 | 52 | files=$(printf '%s\n' "$@") |
|
| 53 | 53 | ;; |
|
| 54 | 54 | esac |
|
| 55 | 55 | ||
| 56 | + | # Check one file per process, in parallel. xargs fails if any check does. |
|
| 57 | + | jobs=$(nproc 2>/dev/null || echo 4) |
|
| 56 | 58 | status=0 |
|
| 57 | - | for f in $files; do |
|
| 58 | - | # shellcheck disable=SC2086 |
|
| 59 | - | out=$("$emulator" $limits -run "$rad" -fmt.check "$prefix$f" 2>&1) || { |
|
| 60 | - | if [ -n "$prefix" ]; then |
|
| 61 | - | printf '%s\n' "$out" | sed "s|$prefix||g" >&2 |
|
| 62 | - | else |
|
| 63 | - | printf '%s\n' "$out" >&2 |
|
| 64 | - | fi |
|
| 65 | - | status=1 |
|
| 66 | - | } |
|
| 67 | - | done |
|
| 59 | + | # shellcheck disable=SC2086 |
|
| 60 | + | out=$(printf '%s\n' $files | sed "s|^|$prefix|" | |
|
| 61 | + | xargs -P "$jobs" -n 1 "$emulator" $limits -run "$rad" -fmt.check 2>&1) || |
|
| 62 | + | status=1 |
|
| 63 | + | if [ -n "$out" ]; then |
|
| 64 | + | if [ -n "$prefix" ]; then |
|
| 65 | + | out=$(printf '%s\n' "$out" | sed "s|$prefix||g") |
|
| 66 | + | fi |
|
| 67 | + | printf '%s\n' "$out" >&2 |
|
| 68 | + | fi |
|
| 68 | 69 | ||
| 69 | 70 | if [ "$status" -ne 0 ]; then |
|
| 70 | 71 | echo "check-fmt: run 'make fmt' or 'radiance -fmt' on the files above" >&2 |
|
| 71 | 72 | fi |
|
| 72 | 73 | exit $status |