Skip to content

Commit f0f3751

Browse files
committed
build: harden low-memory selfdev builds
1 parent 607bd66 commit f0f3751

2 files changed

Lines changed: 39 additions & 14 deletions

File tree

docs/COMPILE_PERFORMANCE_PLAN.md

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,25 @@ Use it when capturing comparable before/after numbers for refactors.
157157
- warm touched-file `selfdev-jcode` build: **18.874s**
158158
- 2026-04-28: diagnosed the repeated self-dev `jcode` lib build `SIGTERM` on this 16 GiB,
159159
no-swap workstation. `journalctl -u earlyoom` showed earlyoom sending `SIGTERM` to the root
160-
`rustc` at about **1.09 GiB RSS** when available memory crossed the 10% threshold. A direct
161-
no-`sccache` build reproduced the same signal, so `sccache` was only reporting the termination.
162-
`scripts/dev_cargo.sh` now enables adaptive low-memory overrides for `--profile selfdev` when
163-
Linux + earlyoom + no swap + <24 GiB RAM + <8 GiB currently available RAM are detected:
164-
`CARGO_INCREMENTAL=0`, `CARGO_PROFILE_SELFDEV_INCREMENTAL=false`, and
165-
`CARGO_PROFILE_SELFDEV_CODEGEN_UNITS=16`. Use `JCODE_SELFDEV_LOW_MEMORY=off` to disable, or
166-
`JCODE_SELFDEV_LOW_MEMORY=on` to force. Validation: the original root build completed under
167-
those settings in **2m34s** after the interrupted partial build reused artifacts; a later
168-
benchmark with 9.4 GiB available showed that preserving the inherited selfdev profile can reduce
169-
warm edit builds from about **60s** to about **14s** when there is enough headroom.
160+
`rustc` when available memory crossed the 10% threshold. A direct no-`sccache` build reproduced
161+
the same signal, so `sccache` was only reporting the termination. `scripts/dev_cargo.sh` now
162+
enables adaptive low-memory overrides for `--profile selfdev` when Linux + earlyoom + no swap +
163+
<24 GiB RAM + <8 GiB currently available RAM are detected: `CARGO_INCREMENTAL=1`,
164+
`CARGO_PROFILE_SELFDEV_INCREMENTAL=true`, and `CARGO_PROFILE_SELFDEV_CODEGEN_UNITS=256`. Use
165+
`JCODE_SELFDEV_LOW_MEMORY=off` to disable, or `JCODE_SELFDEV_LOW_MEMORY=on` to force. Initial
166+
validation completed under the earlier settings in **2m34s** after an interrupted partial build
167+
reused artifacts; a later benchmark with 9.4 GiB available showed that preserving the inherited
168+
selfdev profile can reduce warm edit builds from about **60s** to about **14s** when there is
169+
enough headroom.
170+
- 2026-05-21: rechecked the same failure mode during overnight TUI test triage. `journalctl -u
171+
earlyoom` showed repeated `SIGTERM` events against root `jcode` `rustc` processes at about
172+
**2.7-3.3 GiB RSS**. `CARGO_PROFILE_SELFDEV_CODEGEN_UNITS=16` still failed under current browser
173+
and desktop-session memory pressure, while a direct no-`sccache` selfdev build with incremental
174+
enabled and `CARGO_PROFILE_SELFDEV_CODEGEN_UNITS=256` completed. The adaptive low-memory default
175+
was changed to match that passing profile, disables `sccache` by default because `sccache`
176+
rejects Cargo incremental builds, and `scripts/dev_cargo.sh` now honors `SCCACHE_DISABLE=1`
177+
before auto-enabling the wrapper. Fresh lib-test compilation remains heavier than the binary
178+
build and may still require a remote builder, more free memory, or swap.
170179
- 2026-05-05: trimmed root compile surface by replacing broad `tokio/full` with explicit used
171180
features, aligning Jcode-owned `crossterm` dependencies on 0.29, and replacing `qr2term` with
172181
direct `qrcode` rendering. This removed the duplicate `crossterm 0.28` path from the `jcode`

scripts/dev_cargo.sh

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ append_rustflags() {
2828
}
2929

3030
maybe_enable_sccache() {
31+
case "${SCCACHE_DISABLE:-}" in
32+
1|true|yes|on)
33+
if [[ -n "${RUSTC_WRAPPER:-}" && "${RUSTC_WRAPPER}" == *sccache* ]]; then
34+
unset RUSTC_WRAPPER
35+
fi
36+
sccache_status="disabled-by-env"
37+
log "sccache disabled by SCCACHE_DISABLE"
38+
return
39+
;;
40+
esac
41+
3142
if [[ -n "${RUSTC_WRAPPER:-}" ]]; then
3243
sccache_status="external:${RUSTC_WRAPPER}"
3344
log "keeping existing RUSTC_WRAPPER=${RUSTC_WRAPPER}"
@@ -174,7 +185,7 @@ selfdev_low_memory_default_needed() {
174185
[[ -n "$mem_total_kib" && -n "$mem_available_kib" && -n "$swap_total_kib" ]] || return 1
175186

176187
# On small no-swap machines, earlyoom can terminate the root jcode rustc
177-
# around 1 GiB RSS before the kernel OOM killer would report anything.
188+
# around 1-3 GiB RSS before the kernel OOM killer would report anything.
178189
# Keep this adaptive so larger workstations, and currently-idle smaller
179190
# workstations with enough headroom, retain the faster inherited selfdev
180191
# profile by default.
@@ -207,9 +218,14 @@ maybe_configure_low_memory_selfdev() {
207218
;;
208219
esac
209220

210-
export CARGO_INCREMENTAL="${CARGO_INCREMENTAL:-0}"
211-
export CARGO_PROFILE_SELFDEV_INCREMENTAL="${CARGO_PROFILE_SELFDEV_INCREMENTAL:-false}"
212-
export CARGO_PROFILE_SELFDEV_CODEGEN_UNITS="${CARGO_PROFILE_SELFDEV_CODEGEN_UNITS:-16}"
221+
export CARGO_INCREMENTAL="${CARGO_INCREMENTAL:-1}"
222+
export CARGO_PROFILE_SELFDEV_INCREMENTAL="${CARGO_PROFILE_SELFDEV_INCREMENTAL:-true}"
223+
export CARGO_PROFILE_SELFDEV_CODEGEN_UNITS="${CARGO_PROFILE_SELFDEV_CODEGEN_UNITS:-256}"
224+
# The low-memory profile deliberately keeps incremental compilation enabled
225+
# to avoid repeatedly rebuilding large root crates. sccache rejects Cargo
226+
# incremental builds, so default to direct rustc unless the caller opts out
227+
# of low-memory mode entirely.
228+
export SCCACHE_DISABLE="${SCCACHE_DISABLE:-1}"
213229
selfdev_low_memory_status="enabled:incremental=${CARGO_PROFILE_SELFDEV_INCREMENTAL},codegen-units=${CARGO_PROFILE_SELFDEV_CODEGEN_UNITS}"
214230
log "using low-memory selfdev overrides (${selfdev_low_memory_status#enabled:})"
215231
}

0 commit comments

Comments
 (0)