Skip to content

feat: lazy declaration watchers and single-process workspace watch - #20

Merged
praveenpuglia merged 3 commits into
masterfrom
praveen/lazy-watch
Oct 7, 2026
Merged

praveenpuglia merged 3 commits into
masterfrom
praveen/lazy-watch

Conversation

@praveenpuglia

@praveenpuglia praveenpuglia commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Problem

lerna run build:watch in sc-fe-components starts one bite process per package (54), and each one eagerly built a full TypeScript watch program. Each program loads and watches every imported file, every auto-included @types/* package and sibling packages' dist/*.d.ts. For example, Accordion has 2 source files but its program loaded 646 files and 214 MB.

Change

On watch startup bite now:

  1. Re-transpiles only sources whose output is missing or older than the source.
  2. Starts the TypeScript watch program only when the package's declarations are stale or one of its files changes.

Idle packages cost only a chokidar watcher on src.

Measured on sc-fe-components (all packages, after a full build)

Before After
Memory (RSS) ~19 GB ~7 GB
inotify watches ~265k (machine limit 275k) ~25k
CPU time to start up 742 s 48 s

The first edit in a package pays for starting its program: ~2.9 s in components. After that, edits take ~0.4 s, the same as before.

Notes

  • Outputs that look up to date aren't rebuilt when watch mode starts. After changing Babel or TS config, run a normal build. The README says so.
  • CreateSmallcases and services use tsx-transform --clean --watch, which wipes dist and so always starts TypeScript at startup. Dropping --clean from those scripts lets them start lazily too.

Workspace mode (--watch --workspace)

Running all 57 per-package watchers with lerna run build:watch --parallel hit EMFILE: too many open files. Each Node process takes one inotify instance, and Linux allows 128 per user by default.

bite-tsx-transform --watch --workspace at the repo root watches every package whose build:watch runs bite, using that script's own arguments (e.g. --src=theming --dist=dist), from a single process. Stale declarations at startup are now generated once instead of keeping a TypeScript watch program alive, so dozens of packages can share the process. A package's watch program still starts on its first edit.

Measured on sc-fe-components with all 55 bite packages, idle:

Process per package --workspace
Processes 55 1
Memory (RSS) ~7 GB ~560 MB
inotify instances 55 1
Startup n/a 4.3 s

Edit latency is unchanged: ~2.3 s for the first .d.ts in components, ~0.3 s after that. Each package edited stays loaded; with two edited it was ~1.1 GB.

Suggested root script in sc-fe-components: "build:watch": "bite-tsx-transform --watch --workspace".

Testing

  • Existing suite passes (8 tests).
  • New test: workspace mode watches two packages with different layouts in one process, skips a package whose build:watch isn't bite, and updates declarations in a --src=lib --dist=out package.
  • New test: watch mode leaves an up-to-date output untouched, doesn't start TypeScript before an edit, and still updates the .d.ts after one. It fails on the previous code.

🤖 Generated with Claude Code

praveenpuglia and others added 2 commits October 5, 2026 22:25
Skip outputs that are newer than their sources on watch startup and
only start a package's TypeScript watch program once it is stale or
edited, so idle packages in a monorepo-wide watch only cost a chokidar
watcher.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
`tsx-transform --watch --workspace` at a workspace root watches every
package whose build:watch runs bite, with that script's arguments. One
process avoids exhausting inotify instances (EMFILE) and the ~125 MB
baseline of a watcher process per package.

Stale declarations at watch startup are now emitted by a one-off program
instead of a long-lived watch program, so many packages can share a
process; the watch program still starts on a package's first edit.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@praveenpuglia praveenpuglia changed the title feat: start declaration watchers lazily in watch mode feat: lazy declaration watchers and single-process workspace watch Oct 5, 2026
The workspace summary was logged before each package's initial scan
finished, so an edit right after it could be missed.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@Daggron Daggron left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@praveenpuglia
praveenpuglia merged commit 71907e0 into master Oct 7, 2026
1 check passed
@praveenpuglia
praveenpuglia deleted the praveen/lazy-watch branch October 7, 2026 06:43
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