Skip to content

perf(check): reduce native typecheck GC CPU with caller-overridable defaults - #2276

Merged
devswha merged 1 commit into
mainfrom
chore/ram-offload
Oct 28, 2026
Merged

devswha merged 1 commit into
mainfrom
chore/ram-offload

Conversation

@devswha

@devswha devswha commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

Change

Default native TypeScript 7 checks to GOGC=400, retaining garbage collection
while spending modestly more RAM to reduce CPU. Typecheck's Go 1.26.4 tsc
was the #2 CPU consumer on the shared P620 CI host.

The original proposal was GOGC=off GOMEMLIMIT=6GiB. The maintainer's concurrency
steer requires sizing for 24 simultaneous typechecks with approximately 40 GB free;
the measurements below rule out a GC-off limit with the requested 1.5x headroom,
so this PR uses the explicitly requested GOGC=400 fallback instead.

  • package.json routes typecheck through a small Bun wrapper. Both CI's
    check fast/check concurrent and the remote-bundle jobs already invoke
    bun run typecheck; neither scripts/check.ts nor any workflow needs editing.
  • The wrapper retains the existing native compiler launcher, both tsconfig
    invocations, sequential execution, inherited stdio, and failure exit codes.
  • Caller GOGC wins, including an explicitly empty value. GOMEMLIMIT is
    never assigned or removed by the wrapper, so caller limits remain in force.
  • The wrapper passes a child environment and argument array, with no POSIX
    environment-assignment syntax or hard-coded Linux compiler path. This preserves
    TypeScript's platform package selection on Linux, macOS, and Windows.
  • Seven subprocess regression cases cover both compiler environments, default
    and independent/combined/empty overrides, argument forwarding, inherited
    unrelated environment, and stopping on either compiler's failure.
  • The explicit tools tsconfig now includes the wrapper and its tests so the normal
    typecheck validates both new files.
  • Includes an English maintenance changelog fragment. No workflow or dependency
    changes.

Concurrency sizing

Direct GNU /usr/bin/time -v measurements of
node_modules/@typescript/typescript-linux-x64/lib/tsc, not Bun's RSS.
Three runs per project and setting, each through dori heavy ram-gogc-pr -- ...;
the table reports the maximum of those three runs. Both projects run sequentially.
Baseline and unlimited-off measurements explicitly remove GOMEMLIMIT.

Native compiler setting Main peak RSS MiB Tools peak RSS MiB
GOGC=100, no limit 1205.29 606.29
GOGC=off, no limit 1400.33 695.16
GOGC=off GOMEMLIMIT=6GiB 1399.34 698.23
Chosen: GOGC=400, no limit 1381.34 684.29

Separate baseline GODEBUG=gctrace=1 traces show largest post-GC live heaps
(X->Y->Z MB, the Z) of 752 MiB main / 394 MiB tools. These are observed
live heaps, not a universal upper bound.

The no-GC main peak times 1.5 is 2100.50 MiB, rounded up to 2112MiB.
That limit alone times 24 is 49.5 GiB, before RSS overhead, exceeding both
the approximately 30 GB target and approximately 40 GB free. Even observed
unlimited-off RSS times 24 is 32.82 GiB / 35.24 decimal GB without growth headroom.
There is no qualifying GC-off limit under the requested sizing rule.

Baseline direct RSS times 24 is 28.25 GiB / 30.33 decimal GB. The chosen
direct peak times 24 is 32.38 GiB / 34.76 decimal GB. The larger observed
full-command high-water RSS gives 32.49 GiB / 34.89 decimal GB.
The decision-relevant increment for these direct peaks is 176.05 MiB per
compiler
, or 4.13 GiB / 4.43 decimal GB at 24: the existing baseline memory
is already consumed without this change. In the prior seven-round CI-image
experiment below, the median increment is 157.00 MiB per compiler, or
3.68 GiB / 3.95 decimal GB at 24.
The fallback is below approximately 40 GB in this measurement but does not
meet the preferred approximately 30 GB envelope
; it leaves about 5 GB for other
memory. GOGC=400 retains collection, not an RSS cap or a guarantee that 24
runners plus their overhead fit. GOMEMLIMIT remains available to the caller.

Twenty-four simultaneous typechecks are a conservative planning case, not the
usual workload: CHECK_HOST_MAX_RUNS=4 bounds the herdr-backed lanes, whereas
typecheck runs in Fast checks on up to 20 runners plus any applicable lanes.
That lane bound is not a global semaphore for every Fast-check compiler.

Performance evidence

Prior CI-image experiment: seven rotating rounds

Source: /home/devswha/.cache/ram-offload-tmp/gogc/results.md, snapshot
adfdef6e49767ec09323b9b2e1f0f151c6b84394, Bun 1.4.2, TypeScript 7.0.2 /
Go 1.26.4, herdr-ci-runner:local on the 128-CPU P620. Medians:

Setting CPU user+sys s Wall s Max RSS MiB
Default 52.31 6.47 1188.54
Chosen fallback: GOGC=400 38.74 (-25.94%) 6.14 (-5.10%) 1345.54 (+157.00)
Rejected: GOGC=off GOMEMLIMIT=6GiB 23.49 (-55.09%) 4.76 (-26.43%) 1390.78 (+202.25)

Every one of the seven GOGC=400 runs used less CPU than the baseline median;
its worst was 47.16 CPU-s versus 52.31 CPU-s.

This worktree: five alternating baseline/chosen comparisons

Rebased onto 792dbb98be8a2cd88b1123930a6aae8b131ebe23; Bun 1.4.3, native
TypeScript 7.0.2 / Go 1.26.4. GNU time wraps the real bun run typecheck.
Baseline supplies GOGC=100; chosen leaves it unset and exercises the wrapper
default. Both remove GOMEMLIMIT. Odd rounds run baseline then chosen, even
rounds reverse that order. All runs use dori heavy ram-gogc-pr -- ....

Round Baseline CPU s Chosen CPU s Baseline wall s Chosen wall s Baseline RSS MiB Chosen RSS MiB
1 59.58 43.57 6.34 7.37 1191.29 1310.29
2 48.88 36.36 8.39 7.83 1174.24 1382.29
3 66.91 42.98 7.38 6.25 1132.29 1386.23
4 58.33 41.24 6.30 6.23 1132.29 1195.29
5 64.05 61.80 9.07 10.97 1194.29 1191.29
Median 59.58 42.98 (-27.86%) 7.38 7.37 (-0.14%) 1174.24 1310.29 (+136.05)

Every chosen run beats its paired baseline on CPU; four of five also beat the
baseline median. Round 5's 61.80 CPU-s exceeds the 59.58 CPU-s baseline median
and is retained. Wall-time improvement is negligible on this busy shared host.
Full-command RSS is GNU time's process-tree high-water statistic, not a sum of
simultaneously resident processes.

For the originally requested chronological three-run before/after comparison:
the unchanged script was measured before tracked edits, so no stash was needed.
Before CPU was 35.10 / 36.17 / 28.64 s, wall 4.32 / 4.95 / 5.94 s, and
RSS 1202.23 / 1206.29 / 1207.29 MiB. The first three after runs are rounds 1-3
above. Their medians are 35.10 -> 42.98 CPU-s, 4.95 -> 7.37 wall-s,
1206.29 -> 1382.29 MiB
. That chronology-only comparison is slower; shared-host
conditions differed between blocks. The alternating comparison above is the
contemporaneous evidence for the win. No result was discarded.

Full-command GODEBUG=gctrace=1 counts: 24 before, 6 after (3 per compiler).
The 0-2 expectation was for GC off; the selected fallback deliberately retains GC.

Raw logs, scripts, and the complete local report are retained at
/home/devswha/.cache/ram-offload-tmp/pr-tmp/ (sizing-results.md,
baseline-*.time, size-*.time, compare-*.time, and *.trace).
The table above uses final/compare-*.time and final/size-chosen-*.time.
An earlier five-round comparison before adding the module marker and tools
typechecking coverage is retained too: medians 55.60 -> 39.74 CPU-s (-28.53%),
7.03 -> 6.74 wall-s, 1193.21 -> 1250.16 MiB. The final tree was remeasured rather
than substituting those earlier results.

Validation

  • dori heavy ram-gogc-pr -- bun test ./scripts/typecheck.test.ts: 7 pass, 0 fail.
  • Native TS7 checks the new wrapper and tests through tsconfig.tools.json.
  • Required local dori heavy ram-gogc-pr -- bun run check fast: exit 0;
    8202 pass, 0 fail, 33 skip in 530 files. Workflow syntax, both generated-file
    freshness checks, both TypeScript projects, build, and unit tests all passed.
    Report e39ee9c2-d32d-4758-89a6-7432c7db8945 has status=success,
    verification.status=verified, source.unchanged=true, and no errors;
    log: check-fast-final.log.
  • Final diff reviewed locally. An independent gate reviewer could not be started
    because this task is already at the harness's maximum subagent depth.
  • Native macOS and Windows runs were not executed locally; portability follows
    the existing launcher and Bun child-environment API, without shell assignments.
  • No live runner service/containers, panes, other worktrees, sysctl, swap, or sudo
    operations. Temporary evidence uses the requested TMPDIR; no shared cleanup.

@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 44bb9f8 and 00df225.

Files selected for processing: 5
  • changelog.d/typecheck-gc.md
  • package.json
  • scripts/typecheck.test.ts
  • scripts/typecheck.ts
  • tsconfig.tools.json

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.

📝 Summary

Summary by CodeRabbit

  • Chores
    • Improved type-checking resource use in CI, reducing CPU consumption while retaining garbage collection. This may increase memory usage during checks.
    • Type checks now run sequentially, and existing environment settings are preserved. If a check fails, later checks stop and the failure is reported.

The typecheck command now uses a Bun script to run checks for the default and tools TypeScript projects in sequence. The script defaults GOGC to 400 only when unset, preserves other environment settings, and stops when a check fails.

Changes: TypeScript check runner

Layer / File(s) Summary
Typecheck orchestration and validation
package.json, scripts/typecheck.ts, tsconfig.tools.json, scripts/typecheck.test.ts, changelog.d/typecheck-gc.md
The typecheck command uses a script that runs both projects in sequence and stops on the first nonzero exit status. Tests cover default and caller-provided GC settings, inherited environment values, and compiler failures. The tools project includes the runner and its tests. The changelog records the GOGC=400 default and CPU/RAM tradeoff.

Priority: Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Merge Risk: Minimal · up to 00df2

Typechecks default to higher memory use in exchange for lower CPU use. No merge-blocking issue was identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely identifies the main change: reducing native typecheck garbage-collection CPU use while allowing caller overrides.
Description check Passed The description includes the required Change and Validation sections. It explains the problem, resulting behavior, implementation scope, performance evidence, limitations, and validation results in su…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description includes the required Change and Validation sections. It explains the problem, resulting behavior, implementation scope, performance evidence, limitations, and validation results in sufficient detail.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files. (3 skipped: 3 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 2
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Deploying ovis with  Cloudflare Pages  Cloudflare Pages

Latest commit: 00df225
Status: ✅  Deploy successful!
Preview URL: https://8bcaebcd.ovis.pages.dev
Branch Preview URL: https://chore-ram-offload.ovis.pages.dev

View logs

@devswha

devswha commented Oct 28, 2026

Copy link
Copy Markdown
Owner Author

Merging 00df225. Codex was at capacity, so the merge pass read the diff and an omo reviewer on gpt-6.1-sol reviewed it; both pass. bun run typecheck now runs scripts/typecheck.ts, which runs the same two tsc --noEmit checks in order with GOGC=400 unless the caller set GOGC (an empty value and GOMEMLIMIT are kept), with inherited output, stopping on the first failure with its exit code. Verified: both projects still fail on a real type error (TS2322, exit 1 through the wrapper as directly); the tests catch a changed default (400 -> 401 fails 2 of 7); Ctrl-C ends it with SIGINT; every caller (scripts/check.ts, remote-bundles.yml, docs) still uses bun run typecheck. The +136 MiB figure matches the lane's sampled medians (about +3.2 to +4.1 GiB at 24 concurrent compilers); GOGC=400 keeps collection but sets no RSS limit. No workflow or live runner change. A GOMAXPROCS cap (min(32, cores)) comes as a small follow-up PR, per the maintainer side (Dori). Not verified: the wrapper on native Windows (process.execPath + '--bun tsc' resolves by inspection).

@devswha
devswha merged commit 4b07d0c into main Oct 28, 2026
46 of 61 checks passed
@devswha
devswha deleted the chore/ram-offload branch October 28, 2026 16:46
devswha added a commit that referenced this pull request Oct 28, 2026
## Change

Follow-up to #2276. Native TypeScript 7 is a Go binary; cap its default
scheduler width at
`min(32, availableParallelism())` alongside #2276's `GOGC=400` default.

- The wrapper sets `GOMAXPROCS` only when the caller did not set it.
- Caller values still win, including an explicitly empty `GOMAXPROCS`.
- Caller `GOGC` still wins under the same rule, and `GOMEMLIMIT` remains
untouched.
- The two native compiler invocations remain sequential and keep their
existing arguments,
  inherited stdio, and failure exit codes.

## Final-tree measurement

Measured on #2276 head `00df2254735dbebb2185e38ee323c6a55eeb6835`,
before this
follow-up. Five rotated rounds ran B/P/N, P/N/B, N/B/P, B/P/N, P/N/B
inside one
`dori heavy ram-gogc-pr` admission.

- B: TypeScript directly, with `GOGC`, `GOMAXPROCS`, and `GOMEMLIMIT`
unset.
- P: #2276 wrapper, default `GOGC=400`, `GOMAXPROCS` unset.
- N: #2276 wrapper, default `GOGC=400`, `GOMAXPROCS=32`.
- CPU is GNU time user + system. RSS is MiB.

| Variant | Median CPU s | Median wall s | Full RSS | Main tsc RSS |
Tools tsc RSS |
| :--- | ---: | ---: | ---: | ---: | ---: |
| B | 87.87 | 11.85 | 1155.18 | 1193.28 | 602.23 |
| P | 67.21 | 12.90 | 1378.33 | 1377.27 | 679.29 |
| **N** | **59.73** | **11.48** | **1181.23** | **1190.29** | **652.23**
|

N versus B: CPU **-32.02%**, wall **-3.12%**, full RSS **+2.26%**, main
RSS
**-0.25%**, tools RSS **+8.30%**.

N versus P: CPU **-11.13%**, wall **-11.01%**, full RSS **-14.30%**,
main RSS
**-13.58%**, tools RSS **-3.98%**.

Every N CPU run was below P's 67.21-second median: **66.90, 50.26,
57.61,
59.73, 67.18**. N also beat P on median CPU and median wall, satisfying
all
predeclared gates. The closest N run was **67.18 seconds versus P's
67.21-second
median**, a 0.03-second margin. No run was discarded.

This was a noisy shared host: the recorded one-minute load average
ranged from
**95.66 to 141.61** at the start of the measured commands (approximately
**95-140**). Rotation and the per-run table retain that noise rather
than hiding it.

### Every run

| Round | Variant | CPU s | Wall s | Full RSS | Main tsc RSS | Tools tsc
RSS | Load averages at start |
| ---: | :---: | ---: | ---: | ---: | ---: | ---: | :--- |
| 1 | B | 85.56 | 11.85 | 1188.33 | 1193.28 | 598.18 | 95.66 / 93.82 /
85.28 |
| 1 | P | 74.32 | 12.90 | 1378.33 | 1377.27 | 681.27 | 102.13 / 95.39 /
86.02 |
| 1 | N | 66.90 | 17.21 | 1166.33 | 1238.34 | 662.28 | 123.21 / 101.22 /
88.26 |
| 2 | P | 54.75 | 9.53 | 1383.27 | 1374.27 | 691.28 | 117.51 / 102.13 /
88.99 |
| 2 | N | 50.26 | 9.56 | 1185.28 | 1190.29 | 664.23 | 110.91 / 101.60 /
89.09 |
| 2 | B | 93.28 | 12.44 | 1141.23 | 1196.34 | 600.17 | 112.24 / 102.57 /
89.68 |
| 3 | N | 57.61 | 10.74 | 1181.23 | 1196.29 | 650.29 | 109.19 / 102.50 /
89.94 |
| 3 | B | 92.47 | 12.33 | 1155.18 | 1197.17 | 602.24 | 107.79 / 102.59 /
90.29 |
| 3 | P | 64.74 | 19.31 | 1381.27 | 1197.29 | 654.29 | 106.67 / 102.84 /
90.71 |
| 4 | B | 82.99 | 11.82 | 1187.24 | 1187.23 | 602.23 | 140.35 / 111.96 /
94.29 |
| 4 | P | 68.66 | 12.73 | 1187.29 | 1380.29 | 679.29 | 141.61 / 114.83 /
95.72 |
| 4 | N | 59.73 | 11.48 | 1230.17 | 1160.29 | 652.23 | 130.71 / 114.34 /
96.07 |
| 5 | P | 67.21 | 13.17 | 1198.34 | 1377.29 | 654.29 | 124.02 / 113.86 /
96.29 |
| 5 | N | 67.18 | 15.52 | 1154.29 | 1166.24 | 650.29 | 122.54 / 114.34 /
96.93 |
| 5 | B | 87.87 | 10.78 | 1143.18 | 1192.23 | 602.23 | 126.01 / 116.25 /
98.13 |

## Concurrency sizing

Median direct main-compiler RSS is 1190.29 MiB with N versus 1193.28 MiB
with B.
At 24 simultaneous main compilers:

- B: **27.97 GiB / 30.03 decimal GB**.
- N: **27.90 GiB / 29.95 decimal GB**.

The median main-compiler RSS is effectively unchanged (-0.25%), while
CPU falls
32.02% versus B and 11.13% versus P. `GOMAXPROCS` limits scheduler
parallelism,
not memory, and caller `GOGC`, `GOMAXPROCS`, and `GOMEMLIMIT` remain
available.

## Validation

On this head (`df345097`, rebased onto main after #2276 merged as
`4b07d0cc`):

- `bun test ./scripts/typecheck.test.ts` (inside check fast): **8 pass,
0 fail**.
- `bun run check fast` through `dori heavy ram-gogc-pr`: **exit 0**;
workflow syntax,
  generated types and themes, typecheck, build, and unit tests all ok;
  **8326 pass, 0 fail, 34 skip in 533 files**.

Co-authored-by: sisyphus-dev-ai <[email protected]>
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.

1 participant