Commit 80894e3a

80894e3a7b34Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified

Description

Compile per-test C at -O1, not -O0 (~3x faster, the real win)

Profiling the windows-mingw test step (still ~14min after the prior tweaks) showed the cost is almost entirely gcc compiling the generated C, which #includes the 5554-line lib/sp_runtime.h (800+ static functions). Counter-intuitively, -O0 is ~3x SLOWER than -O1 for this: at -O0 gcc emits code for every referenced static fn from the header, while at -O1 it prunes unreferenced statics and runs DCE before the expensive codegen stages, emitting far less.

Measured per-test compile+link (gcc): -O0 0.75s vs -O1 0.25s. Full local suite wall: -O0 47s vs -O1 16s. 846 pass at -O1 on both gcc and clang.

So the prior commit's premise (-O0 cuts cc time; the step is spawn/latency bound) was wrong: it's CPU-bound on header compilation. Switch every test compile to OPT=-O1 (both CI test steps and the local check / gate-test targets) and drop the -j oversubscription back to nproc (no gain for CPU-bound work). The harmless wins from before -- plain gcc for the test compile, Defender off, one-shot compile+link -- stay.

Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]

Details

Commit
80894e3a7b34
Parent
e0b99da624c0

.github/workflows/ci.ymlmodifiedView file

@@ -54,11 +54,12 @@
5454 run: make -j$(getconf _NPROCESSORS_ONLN) LTO=0 all
5555
5656 - name: Run tests
57- # OPT=-O0 cuts cc time per test (each .rb compiles its own
58- # generated C with $(CFLAGS) -Werror). Type-checking still
59- # happens; we just skip the optimizer.
60- # -j$(...) overlaps the per-test cc invocations.
61- run: make -j$(getconf _NPROCESSORS_ONLN) test OPT=-O0
57+ # OPT=-O1, counter-intuitively, compiles each test ~3x FASTER than
58+ # -O0: the generated C pulls in lib/sp_runtime.h (800+ static fns), and
59+ # at -O1 gcc/clang prune unreferenced statics + DCE before the costly
60+ # codegen stages, emitting far less than -O0 does. -j overlaps the
61+ # per-test cc invocations.
62+ run: make -j$(getconf _NPROCESSORS_ONLN) test OPT=-O1
6263
6364 # Benchmark integration test. Compiles every benchmark/*.rb through
6465 # the full pipeline (cc -Werror) and diffs the output against CRuby.
@@ -149,12 +150,13 @@
149150 run: make -j$(nproc) LTO=0 all
150151
151152 - name: Run tests
152- # Oversubscribe -j (process-spawn/link-latency bound on Windows, not
153- # CPU bound) and use plain gcc: each test's generated C is unique, so
154- # the sccache wrapper only adds miss-overhead per compile here (the
155- # build step above keeps sccache, where caching the runtime/prism
156- # objects pays off).
157- run: make -j$(( $(nproc) * 2 )) test OPT=-O0 CC=gcc
153+ # OPT=-O1 is the big lever here: each per-test cc compiles the
154+ # sp_runtime.h-heavy generated C ~3x faster than at -O0 (gcc prunes the
155+ # 800+ unreferenced static fns before codegen). Plain gcc (not the
156+ # sccache wrapper): the generated C is unique per test so sccache only
157+ # adds miss-overhead; the build step above keeps sccache where caching
158+ # the runtime/prism objects pays off.
159+ run: make -j$(nproc) test OPT=-O1 CC=gcc
158160
159161 - name: sccache stats
160162 if: always()