Commit 9e9f4c05
9e9f4c056a8bMerged
Ryan Seys <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
chore(test): default -j to logical CPU count when no -j was passed
Bare make test runs the 345 test recipes serially through a single
worker — ~2× slower than necessary on multi-core machines. This adds
an auto-detect block that sets -j$(NPROC) in MAKEFLAGS when the
command line didn't supply one.
The combined guard catches the three forms a user can supply -j in (per the GNU Make manual):
-j N/-jN—filter -j%-kj(short cluster) —findstring jinfirstword -$(MAKEFLAGS)(the leading-keeps firstword non-empty when MAKEFLAGS starts blank)--jobserver-auth=…—filter --jobserver%(Make 4.x long form)
CI (which already passes -j$(getconf _NPROCESSORS_ONLN)) is
unaffected: the explicit -j is detected and the guard skips. NPROC
falls back to 4 when getconf is unavailable.
Caveat: GNU Make 3.81 (still bundled with macOS) reports MAKEFLAGS
as empty at parse time even when the user passed -j, so the guard
always fires and the user's command-line -j is silently overridden.
Workaround: pass via env var, e.g. MAKEFLAGS=-jN make test.
Modern Make (4.0+, used by Linux CI and brew gmake) is unaffected.
Performance (macOS, M-series 12 logical cores, 345 tests, bare
make test with no -j flag):
scenario master after speedup
cold (1st run) 143.0 s 73.6 s 1.9x warm (2nd run) 101.4 s 44.7 s 2.3x
cold is the first make test immediately after
make clean && make all && make bootstrap. warm is the next
make test invoked right after, where OS-level filesystem caches
and ccache (when present) are hot from the cold run. master's
make test always wipes .ok files first via clean-test-results,
so neither run benefits from per-test result caching — the warm
speedup is purely OS / ccache state.
Speedup is bounded by REF_RUBY invocations and per-test diff/cmp which serialize more than the parse/codegen/cc/run pipeline; on machines where the compile step dominates (no ccache, more cores) the speedup grows accordingly.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 9e9f4c056a8b
- Parent
- e438d961b51c
MakefilemodifiedView file
TIMEOUT10 := $(if $(TIMEOUT_BIN),$(TIMEOUT_BIN) 10,)TIMEOUT60 := $(if $(TIMEOUT_BIN),$(TIMEOUT_BIN) 60,)# Default -j to logical CPU count when MAKEFLAGS doesn't already# carry a -j flag. The combined guard catches the three forms a user# can supply -j in (per the GNU Make manual): `-j N` / `-jN` via# filter, the short-flag-cluster form like `-kj` via findstring on# the first word (the leading `-` makes firstword non-empty when# MAKEFLAGS starts blank), and Make 4.x's `--jobserver-auth=…` long# form. Note: GNU Make 3.81 (macOS system make) reports MAKEFLAGS# as empty at parse time, so the guard always fires there; users on# 3.81 wanting to override should pass `MAKEFLAGS=-jN make …`.ifeq (,$(filter -j%,$(MAKEFLAGS))$(findstring j,$(firstword -$(MAKEFLAGS)))$(filter --jobserver%,$(MAKEFLAGS))) MAKEFLAGS += -j$(shell getconf _NPROCESSORS_ONLN 2>/dev/null || echo 4)endif# Reference Ruby for `make test` / `make bench` output comparison.# Defaults to `ruby` (the system CRuby), matching the historical# behaviour. Override on the command line when a newer or differently-