Skip to content

Build: parallel build-graph executor with memory-claim admission (study delta 8) #680

Closed

Description

@ehartford

Part of #679. run_build_graph is a single for-loop in declaration order (src/main.w:~1570); deps drive only cache staleness, never scheduling. The ~30 runtime/bridge objects run back-to-back (~90s serial tail in build-times.tsv) on one core of 16. References: Go work/exec.go Builder.Do ready-queue at GOMAXPROCS; Zig build_runner.zig:1419-1438 dispatches steps with max_rss admission control (steps park until their declared memory claim fits the host budget). Adopt: topological ready-queue + windowed process pool + per-target memory claim, written in With (lib/std/build.w:627 parallel() already exists — the compiler's own build never calls it). Expected: object tail ~90s → ~15s; prerequisite-multiplier for separate compilation (#684-class work). No cache-format changes.

Activity

  1. ehartford commented on Jul 18, 2026

    @ehartford
    ContributorAuthor

    Design (settled 2026-07-18, groundwork commit in flight):

    Key discovery: with_object_target and the stage compiles are all kind .Action (build.w:27-39), and Action/Test targets already delegate to child processes via with build :name --no-deps + WITH_BUILD_ACTION_WORKER/WITH_BUILD_TEST_WORKER + FORCE env (src/main.w:1310-1355). The scheduler is therefore a dispatch-loop change, not a threading change: spawn the same workers CONCURRENTLY with with_exec_argv_capture_spawn (already exists, returns pids — BuildGraphRuntime.w:5) and schedule by the dep graph. setenv-then-spawn pairs are race-free in the single-threaded driver.

    Stage A (landing now): edge audit at graph load — hard-error on duplicate primary outputs; enumerate producer→consumer relationships lacking a declared dep (today declaration order is load-bearing); note extra_outputs shared by multiple targets (write race under any scheduler; emit-c-test and emit-c-roundtrip both write out/gen/wl_decls.h + wl_stubs.c with no mutual edge). Follow-up A2: add the missing .dep() edges explicitly in build.w. CRITICAL: never feed synthesized/ordering edges into the dep_rebuilt staleness rule — a byte-identical producer rerun would re-invalidate consumers, the exact #650/D13 trap.

    Stage B: ready-queue scheduler. Topo order over explicit deps (+ serialization edges for shared extra_outputs); spawn ready Action/Test targets up to W in flight (default cores/2, env override); retire via per-pid wait; per-inflight [time] entries flushed at retire; worker stdout/stderr captured per target and printed on retire; first failure stops new spawns, drains in-flight, exits with the failure rc (run-all within the wave, no mid-wave abandon). Workers already self-record cache state; parent records only what it executes in-process.

    Stage C: delegate remaining in-process kinds (CompileC/Asm/LlvmIrObject, Exe/Lib/Object/Archive) through the same worker path so the ~90s serial object tail parallelizes. Each worker pays the ~1.1s build.w re-eval tax (#683 removes it); acceptable at 16-wide for 3s targets.

    Stage D: memory-claim admission (Zig build_runner.zig:1419-1438 model): per-target claim field in build.w API with kind-based defaults (stage compile ~6 GB, object ~500 MB, test ~300 MB); a ready target parks until claims-in-flight + its claim fit the host budget. Prevents W stage-compiles from stacking 30 GB. Gate B behind A2 completeness; land B/C/D as separate battery cycles (executor semantics — NOT D14 batch-eligible).

  2. ehartford commented on Jul 18, 2026

    @ehartford
    ContributorAuthor

    Stage A LANDED (76c6d96 audit + 0262e1e edges, one D14 batch battery, GATES EXIT: 0).

    Audit findings on the real build closure: 29 undeclared producer edges — embedded-objects-asm x13 (both legs), stage2 and link-compiler each missing compiler-main-source (stage1 had it), regex-runtime-object missing regex-runtime-ir. All declared; the closure now audits clean and the audit runs on every graph load, so regressions self-report.

    Design correction from testing: build_graph_validate_outputs already hard-rejects duplicate outputs (primary AND extra) per filtered graph — the shared-extra-output serialization concern in the earlier comment is moot within any single invocation; the scheduler inherits single-writer from existing validation. The emit-c pair never co-schedules (separate closures).

    Post-edge verification: the full-chain battery showed no new invalidation cascades from the 29 edges (47 executed = expected set for a build.w change).

    Stage B (ready-queue concurrent scheduler) is now unblocked and should start from this commit pair.

  3. ehartford commented on Jul 18, 2026

    @ehartford
    ContributorAuthor

    Stage B LANDED and measured: a2413f2 (pool machinery + allow_parallel API, inert) + 44ab0d2 (marker flip) with the intermediate reseed the two-commit bootstrap rule requires — build.w cannot name a stdlib API until a seed embeds it.

    Mechanism as designed: declaration order stays the program order; allow_parallel kind-23 targets spawn as captured workers (width cores/2, WITH_BUILD_JOBS override), retire oldest-first with output replay and per-worker [time]; the pool drains before any unmarked execution or dependent target. Pool proof: two 2s actions in 3.1s wall. Fixpoint remained byte-identical on pooled builds (no nondeterminism introduced).

    Measured full-chain rebuild: 684.2s vs 757.8s serial baseline (~10%). The object/IR tail now runs as waves; remaining time is the inherently serial stage chain (stage1 190.5 + stage2 191.4 + link 189.1 = 83%) — separate compilation (#684) is the only lever on that. One landmine documented for future stdlib field additions: Target has three full copy-literals (Target.target/optimize/output) that must gain any new field; missing them ships a broken embedded stdlib that only surfaces in behavior tests spawning out/stage/bin/with-stage2.

    Remaining stages: C (delegate in-process kinds through the worker path so CompileC/Asm/LlvmIr/Exe targets pool too), D (memory-claim admission before widening further). Both need fresh cycles.

  4. added a commit that references this issue on Jul 18, 2026
  5. ehartford commented on Aug 31, 2026

    @ehartford
    ContributorAuthor

    Triage re-scope 2026-08-31: stage B landed (44ab0d2 — windowed pool for object/IR compile targets, measured 757.8s→684.2s, fixpoint identical). Remaining scope: stage C — route the remaining in-process target kinds (regex-runtime-object, bridges, ~8s bound) through the pool, and add per-target memory-claim admission (Zig max_rss model) so pool width degrades under the build memory ceiling.

  6. added 3 commits that reference this issue on Sep 1, 2026
  7. ehartford commented on Sep 1, 2026

    @ehartford
    ContributorAuthor

    Status check against the current tree (2026-09-01, after #921 runner phases 0/1 and #680 phase A, 22df751):

    • Object targets are already pooled: with_object_target sets allow_parallel(), and the test lanes pool with width admission.
    • The serial object tail this issue measured at ~90s is gone. A full with build today: 20 targets executed, 156s total, of which stage2 70s + link-compiler 69s; the slowest object is regex-runtime-ir at 6.4s and the rest are 1–3s. :dev: 22 executed, 90s, stage1 65s.
    • Not delivered: per-target memory-claim admission (the Zig max_rss half). Pool admission is by width only. Peak per-target RSS on a full build is 492M (regex-runtime-ir), so on this host the claim system has nothing to park; it would matter on a memory-constrained CI runner or if Compiler: separate compilation with module interface artifacts (study delta 5 — endgame) #684-class separate compilation multiplies concurrent workers.

    Maintainer's call whether the remaining memory-claim piece keeps this open or folds into #702's budget work.

  8. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): done. The executor schedules by readiness: the battery runs gate, uat and survey as one graph scheduled together by readiness and remaining path (tools/battery.w), object and test lanes pool, targets declare rss_limit for admission, and the lane pool is bounded by memory at 2 GiB a lane (build_graph_pool_width_for, #2603).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions