Skip to content

compiler: parallelize stage1 skargo builds and overlap the tail builds - #1717

Merged
mbouaziz merged 2 commits into
mainfrom
vibe/compiler-build-speed-5f646d
Nov 19, 2026
Merged

mbouaziz merged 2 commits into
mainfrom
vibe/compiler-build-speed-5f646d

Conversation

@mbouaziz

@mbouaziz mbouaziz commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Speed up make STAGE=1 (building the compiler) at the build-system level, in three commits:

  1. Pass --jobs $(SKARGO_JOBS) to the stage1/stageD skargo invocations. The Makefile comment claimed the pinned stage0 bootstrap skargo "predates --jobs" — stale: the pinned bootstrap supports --jobs (verified via --help and full builds), including the heavy-unit rule that keeps the compiler self-build (which peaks near the CI job's 14 GiB memory guard) on a slot of its own.
  2. Overlap the tail builds. The stageN/lib/libstd.sklib build runs concurrently with the stageN/bin/skargo build (both ordered after the bins build, which must stay alone for memory reasons). The lib build uses its own stageN/target-lib target dir, so the two concurrent skargo processes never share a target dir and race on the per-unit state.db files (make -j on skiplang/compiler races on shared stage target dir (state.db collisions, libbacktrace configure race) #1581). Applied to stage1/2/3.
  3. Reuse the built libbacktrace.a. libbacktrace's configure+make ran once per output dir (build/, stage0/lib, and every skargo-driven prelude build via build-script-std). Both reuse paths already existed: the prelude Makefile copies $(LIB_DIR)/libbacktrace.a when present (stage0/lib now passes LIB_DIR=build), and prelude/build.sk uses ./build/libbacktrace.a when present (the grouped prelude rule now stages the archive there as a side effect — deliberately not a Makefile prerequisite, since the stage aggregates recurse through sub-makes and a prereq on build/libbacktrace.a would make several make levels run the grouped recipe concurrently, racing in the same configure dir).

tools/test_bootstrap_modules.py is updated to assert the new #1581 invariant (shared-target rules stay prerequisite-ordered; lib build in its own target-lib; all stage skargo invocations pass --jobs).

Motivation

make STAGE=1 is the CI compiler job's critical path. Profiling a fresh build on a 17-core/17 GiB sandbox shows where the wall time goes:

phase before after
stage0 (gunzip + prelude C + 3 clang links + libstd.sklib) ~150s ~127s
stage1 bins: dependency chain of small units ~85s ~56s
stage1 bins: skc [skc] self-compile (skc process ~338s + single-module clang link ~72s) ~428s ~428s
stage1 bins: skc [skfmt] ~31s ~31s
stage1 skargo bins + lib tail ~64s serial ~32s concurrent

The self-compile dominates and is sequential by design: the release profile builds with skc --one-shot --no-incremental-backend (bounded memory; measured the incremental backend at 567s+ for the self-compile, so one-shot is the right choice), the pinned bootstrap emits a single concatenated LLVM module (so SKC_NATIVE_ARTIFACT_WORKERS does not apply, as CI already notes for release builds), and SKC_PARALLEL_PHASES only covers the incremental path's maps, not the one-shot specializer/optimizer. Those levers are bootstrap-pinned for stage1 and memory-bounded in CI, so this PR takes the safe build-level wins.

Measurements (fresh make clean && make STAGE=1, 17-core/17 GiB sandbox, LLVM 20.1.8)

  • before (main): 738s
  • after commit 1+2: 720s
  • after commit 3 (libbacktrace reuse): 666s (~10% total; libbacktrace configure now runs once per build instead of 3x)
  • repeat make STAGE=1 (no changes): 2s no-op, rc=0

Validation

  • Fresh make clean && make STAGE=1 with all three commits: rc=0 in 666s; stage1/bin/{skc,skfmt,skargo} and stage1/lib/libstd.sklib all produced.
  • Repeat make STAGE=1: 2s no-op (fingerprints intact with target-lib).
  • stage1/bin/skc --version → skc 0.4.7 (a0519d7f); compiled and ran a hello-world with stage1/bin/skc against stage1/target/host/release/deps.
  • python3 tools/run_backend_tests.py --compiler stage1/bin/skc --sysroot stage1/target/host/release/deps --legacy-compiler stage0/bin/skc --scratch ... test_release_pipeline test_parallel_clang_accounting test_bootstrap_modules → all passed.
  • python3 -m unittest discover -s skiplang/compiler/tools → 195 tests OK (140 skipped without a compiler env); black --check clean.
  • make -n STAGE=1 parses; Makefile/AGENTS.md are not formatter-covered.

CI

First pipeline failed only in backend-regressions: test_stage_skargo_builds_are_serialized_under_j pinned the old prerequisite edge (stage1/lib/libstd.sklib ordered after stage1/bin/skargo). Fixed by updating the test to the new invariant (commit 2). Second pipeline: all 21 checks passed.

AI assistance: changes made with Mistral Vibe (mistral-large-4-0); validation performed in-session as described above.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

mistral-vibe and others added 2 commits November 19, 2026 23:03
- Pass --jobs $(SKARGO_JOBS) to the stage1 (and stageD) skargo
  invocations: the pinned bootstrap skargo supports --jobs, so the old
  comment claiming stage1 stays serial was stale. skargo's heavy-unit
  rule still keeps the self-compile (which peaks near the CI memory
  guard) on a slot of its own.
- Run the stageN lib build concurrently with the stageN skargo build
  (both after the bins build, which must stay alone): the lib build now
  uses its own stageN/target-lib so the two never share a target dir
  and race on the per-unit state.db files (#1581).

Fresh `make STAGE=1` on a 17-core/17 GiB sandbox: 738s -> 720s. The
remaining wall time is the skc self-compile (~428s), which is
sequential by design in the one-shot release pipeline of the pinned
bootstrap compiler.

Co-Authored-By: mistral-large-4-0 (Mistral AI, via Mistral Vibe) <noreply@mistral.ai>

Co-authored-by: mbouaziz <mbouaziz@users.noreply.github.com>
…b split

test_stage_skargo_builds_are_serialized_under_j pinned the old
prerequisite edge (lib ordered after skargo because all three stage
skargo invocations shared stageN/target). The lib build now uses its
own stageN/target-lib, so the #1581 invariant is: rules sharing
stageN/target stay prerequisite-ordered (bins first, skargo after
it), while the lib build may run concurrently with the skargo build.
Assert the new prereqs, the distinct target dirs and the --jobs flags.

Co-Authored-By: mistral-large-4-0 (Mistral AI, via Mistral Vibe) <noreply@mistral.ai>

Co-authored-by: mbouaziz <mbouaziz@users.noreply.github.com>
@mbouaziz
mbouaziz force-pushed the vibe/compiler-build-speed-5f646d branch from 07a89ab to af01c4f Compare November 19, 2026 23:04
@mbouaziz
mbouaziz marked this pull request as ready for review November 19, 2026 23:04
@mbouaziz
mbouaziz merged commit c5671ba into main Nov 19, 2026
1 check was pending
@mbouaziz
mbouaziz deleted the vibe/compiler-build-speed-5f646d branch November 19, 2026 23:04
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.

3 participants