Skip to content

Comptime evaluator: reads share text, StringBuilder is one growable buffer, calls don't clone the caller's source — linux-sysroot 58.7 GB → 900 MB (#1944) - #1989

Merged
ehartford merged 1 commit into
wave-semafrom
wave-eval
Oct 3, 2026
Merged

ehartford merged 1 commit into
wave-semafrom
wave-eval

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Fixes #1944. Measured with the build-action worker: x86_64 linux-sysroot under the evaluator was SIGKILLed at 58.7 GB (the issue's failure); now 41.7 s, 879 MB, pack byte-identical to the native runner's (13c29966…). aarch64 sysroot on the Mac under a 2 GiB cap: OOM before, 52 s / 864 MB after (e8d4b0ec…, the verified ARM pack). Native runner for comparison: 276 MB — evaluator at 3.3×. Causes (lldb): extra_value_at deep-cloned the value on every read (a 248 KB file copied once per byte read); StringBuilder stored one value per push with no release; every user call cloned the caller's 187 KB source. Fixture behav_1944_comptime_string_builder_bytes.w (1 MB byte-by-byte push, RSS delta bound) fails on the seed and on main's stage1, passes after, on Mac and Linux. Gate green. Joins the next campaign stack.

@ehartford
ehartford changed the base branch from main to wave-sema October 3, 2026 04:00
@ehartford
ehartford added this pull request to stack #1992 October 3, 2026 04:00
…#1944)

The evaluator ran the linux-sysroot build action to 58.7 GB and SIGKILL
(x86_64, eric-5090), and 8 GiB in 23 s on the aarch64 pack (Mac), where the
native runner needs 276 MB. A from-scratch build driven by a non-seed
compiler takes this path before its runner exists.

Three allocation sites, found with lldb on the forced worker:
- extra_value_at deep-cloned every arena read: `self.bytes[i]` in the
  abilists reader cloned the 248691-byte text per byte read
  (with_str_clone_ref <- comptime_value_clone <- extra_value_at <-
  eval_field_access). It now shares the refcounted text, as
  extra_snapshot_value_at already did; write_binary, the one site that
  moved arena text into an owning str, clones there.
- StringBuilder was a chain of CV_STRING_CHUNK arena values, three blocks
  per push, every chunk cloned twice to materialize, nothing released. A
  builder is now an index into the evaluator's Vec[StringBuilder]: push
  appends in place, len reads the buffer, to_str makes the one copy.
- eval_fn_symbol_call_values_with_resolved_type_args cloned the caller's
  whole source text (build/sdk.w, 187 KB) on every user call for call-site
  defaults; it is now read only when a #line/#src default needs it.

Measured, linux-sysroot under the evaluator (worker harness):
  x86_64, eric-5090: 17.0 GB at the 16 GiB cap in 33 s -> 900 MB, 29.9 s,
    pack byte-identical to the native runner's (sha256 13c29966...).
  Same via the driver (stage1 build :linux-sysroot --no-deps): SIGKILL at
    58.7 GB after 250 s -> 879 MB, 41.7 s.
  aarch64, Mac: OOM at an 8 GiB cap in 23 s -> 864 MB, 52.1 s, pack sha256
    e8d4b0ec..., the verified ARM pack.
  Native runner, x86_64: 276 MB, 21.9 s. The evaluator is within 3.3x.

behav_1944_comptime_string_builder_bytes runs the evaluator worker on an
action that pushes 1 MB byte by byte, and bounds its peak RSS over the same
action at 1 byte. Before: +214 MiB (Mac, seed) and +209 MiB (Linux, main).
After: passes on both hosts.

Found on the way: `with check` accepts method calls with the wrong argument
count (#1973). Seven stale call sites here passed check and failed only in
the LLVM verifier.
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery GREEN on stack top 0f13a62 (seed-driven, with run tools/battery.w; stack #2007 = #2005 → #1980 → #1989, on main 3044b9c): gate rc=0 wall=1040s, battery-checks rc=0 wall=521s. The prior run of #1980+#1989 was RED on two regressions in #1980's own fixes (a type-parameter frame restored in the wrong order — three sites; trait contract returns published after default bodies needed them) plus a codegen terminator bug they exposed; all fixed in-layer. #2005's per-process captures held this run steady under load. Merged by the coordinator per Eric's standing direction.

@ehartford
ehartford marked this pull request as ready for review October 3, 2026 05:49
@ehartford
ehartford merged commit 0c10fd6 into main Oct 3, 2026
@ehartford
ehartford deleted the wave-eval branch October 3, 2026 05:49
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.

Comptime evaluator: 63 GB heap on the linux-sysroot action (StringBuilder per-byte values, no reclamation)

1 participant