Skip to content

feat: bound what the TypeScript check's worker may hold with memoryLimit - #386

Closed
alexander-akait wants to merge 2 commits into
mainfrom
feat/ts-memory-limit
Closed

alexander-akait wants to merge 2 commits into
mainfrom
feat/ts-memory-limit

Conversation

@alexander-akait

@alexander-akait alexander-akait commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Part of the performance series (#376–#385). This one bounds memory rather than saving it.

Problem

The TypeScript check's worker thread could hold as much heap as Node gives a thread, and nothing capped it. fork-ts-checker-webpack-plugin sets a memoryLimit (default 2048 MB, as --max-old-space-size on its process), and ts-checker-rspack-plugin defaults to 8192 MB.

Change

  • New option, memoryLimit (MB, minimum 16). It's handed to the worker as resourceLimits.maxOldGenerationSizeMb; jest-worker 30.5 forwards it.
  • What happens past the limit: jest-worker rejects the run with "Jest worker ran out of memory and crashed", and webpack's process carries on. The check then:
    • reports the limit: "ran out of the N MB of memory memoryLimit lets its worker hold: raise it, or set skipLibCheck to check less";
    • drops the worker, so the next build starts the program from nothing.
  • Why 16 is the minimum: at 1 MB, V8 can't even start the thread's isolate ("Fatal JavaScript out of memory: GC during deserialization") and ends the whole process. 16 MB fails gracefully.
  • Default: unset, so behaviour is as before.
  • README section, options-table entry, schema (validators regenerated), changeset and types are updated.

Measured

301 files, TypeScript check on its worker, one-shot:

memoryLimit wall CPU peak RSS result
unset 4.05 s 10.8 s 588 MB clean
512 4.43 s 11.2 s 555 MB clean
256 4.80 s 12.4 s 570 MB clean
160 4.62 s 13.5 s 474 MB reports the limit

Near the limit the collector works harder, so this is for keeping a runaway program from taking the build down, not for speed. The README says so.

Tests

  • New (in test/typescript/threads.test.js): with memoryLimit: 16, the check reports the limit, and the next build without it reports the usual TS2322. With the option not handed to the worker, this test fails. It's skipped where there's no thread to spare, since the check then runs on webpack's thread, which the limit isn't for.
  • Full suite: 315/315, global module path cleared, as on CI. eslint, tsc, prettier, cspell and lint:schema are clean.

Generated by Claude Code

Summary by CodeRabbit

  • New Features
    • TypeScript checks now support an optional worker memory limit, specified in megabytes. The minimum allowed value is 16 MB; without a limit, the worker may use as much memory as Node.js allows.
  • Bug Fixes
    • When a TypeScript check exceeds its worker’s memory limit, the issue is reported and the worker starts from scratch on the next build.
    • Memory-limit errors now indicate whether a custom limit was set and suggest ways to address the issue.
  • Documentation
    • Added guidance on configuring the memory limit and its behavior.

The worker a TypeScript check runs on held as much as Node gives a
thread, and a runaway program had nothing to stop it short of that.

`memoryLimit` (MB, at least 16) is handed to the worker as
`maxOldGenerationSizeMb`. Over it, jest-worker rejects the run; the
check reports the limit, drops the worker, and the next build starts
the program from nothing. Below 16 MB V8 cannot start the thread at
all and ends the process, hence the minimum.

It bounds memory rather than saving it: 301 files peaked at 588 MB
without a limit, 555 MB under 512 MB at +10% time, and ran out under
160 MB, as reported.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01App18sYbe6Vf6HDCjCXbvf
@linux-foundation-easycla

linux-foundation-easycla Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

CLA Not Signed

One or more co-authors of this pull request were not found. You must specify co-authors in commit message trailer via:

Co-authored-by: name <email>

Supported Co-authored-by: formats include:

  1. Anything <id+login@users.noreply.github.com> - it will locate your GitHub user by id part.
  2. Anything <login@users.noreply.github.com> - it will locate your GitHub user by login part.
  3. Anything <public-email> - it will locate your GitHub user by public-email part. Note that this email must be made public on Github.
  4. Anything <other-email> - it will locate your GitHub user by other-email part but only if that email was used before for any other CLA as a main commit author.
  5. login <any-valid-email> - it will locate your GitHub user by login part, note that login part must be at least 3 characters long.

Alternatively, if the co-author should not be included, remove the Co-authored-by: line from the commit message.

Please update your commit message(s) by doing git commit --amend and then git push [--force] and then request re-running CLA check via commenting on this pull request:

/easycla

@codecov

codecov Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.64%. Comparing base (dc3ff2f) to head (80e2f61).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #386      +/-   ##
==========================================
+ Coverage   99.62%   99.64%   +0.01%     
==========================================
  Files          19       19              
  Lines        5400     5649     +249     
==========================================
+ Hits         5380     5629     +249     
  Misses         20       20              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 11 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ad640fa0-220e-4305-b36f-336168e1128b
📥 Commits

Reviewing files that changed from the base of the PR and between f2a9ea0 and 80e2f61.

📒 Files selected for processing: 3
  • .changeset/ts-memory-limit.md
  • README.md
  • src/checks/typescript.json

Walkthrough

The TypeScript check now accepts an optional worker memory limit in megabytes, with a minimum of 16. The checker passes the limit to the worker’s heap configuration. After worker errors, the checker removes and ends the worker; memory-exhaustion errors receive a specific message that retains the original error as its cause. The README and changeset describe the option, and a test covers limited and unrestricted worker runs.

Priority: ➖ Normal

Merge Risk: 🔵 Low · up to f2a9e

The memory limit may not provide the protection described, particularly when Node starts with an explicit heap flag. Clarify these limitations before merge or accept the bounded documentation risk.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 5 files. (3 skipped: 3… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly identifies the main change: adding a memoryLimit option to bound the TypeScript check worker's memory usage.
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: Docstring Coverage

Explanation

Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 5 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 60f54a48-b910-4428-9e6d-b822b15ac629
📥 Commits

Reviewing files that changed from the base of the PR and between 3dbe588 and f2a9ea0.

📒 Files selected for processing: 8
  • .changeset/ts-memory-limit.md
  • README.md
  • src/checks/typescript.check.js
  • src/checks/typescript.js
  • src/checks/typescript.json
  • src/threads.js
  • test/typescript/threads.test.js
  • types/threads.d.ts

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

Comment thread README.md Outdated
Comment thread src/threads.js

Copy link
Copy Markdown
Member Author

EasyCLA fails because the commits carry a Co-Authored-By: Claude trailer that maps to no GitHub account. It is not a code failure. Whether to drop the trailer or accept the check is for the maintainers to decide, so I haven't rewritten history.


Generated by Claude Code

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.

2 participants