Skip to content

perf: Run JavaScript and declarations watchers in single process - #942

Open
aXenDeveloper wants to merge 9 commits into
canaryfrom
claude/nice-meitner-aaynzh
Open

aXenDeveloper wants to merge 9 commits into
canaryfrom
claude/nice-meitner-aaynzh

Conversation

@aXenDeveloper

Copy link
Copy Markdown
Owner

Description

What?

Refactored the package watch runner to execute both JavaScript and declarations watchers within a single child process instead of spawning separate processes for each. The package-watch.ts script now accepts multiple output arguments and creates multiple tsdown watchers that share the same Node process.

Key changes:

  • Modified package-watch.ts to parse multiple output types from command arguments and create watchers for each
  • Refactored the print function into a printer factory that creates output-specific loggers
  • Updated watchPackage calls to run concurrently via Promise.all
  • Updated process cleanup to close all watchers before exiting
  • Modified packageWatchers in watchers.ts to pass both "javascript" and "declarations" arguments to a single runner process
  • Updated test expectations to reflect the reduced process count (from 3 to 2)

Why?

This optimization reduces memory overhead by consolidating two separate Node processes into one. Since TypeScript 7 runs the compiler in a separate native process behind an async API, both watchers can coexist in the same Node heap without blocking each other. The package now pays for one Node heap instead of two, while maintaining the same non-blocking behavior where JavaScript rebuilds never wait for declarations.

The change also simplifies the process management in the dev command by reducing the number of child processes that need to be spawned and tracked.

`vitnode dev` in a plugin package started tsdown twice - one Node process
for the JavaScript and one for the declarations - because the TypeScript
compiler used to block the thread it ran on. With TypeScript 7 the compiler
runs in a separate native process behind an async API, so both watchers can
share one runner without a JavaScript rebuild waiting for declarations.

Measured over the six package watchers `pnpm dev` starts: steady RAM
7.6 GB -> 6.4 GB, startup peak 9.2 GB -> 8.3 GB; JavaScript rebuild latency
in @vitnode/core unchanged (~2 s).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CnAiFa6kGTMFMW42Wy4HFj
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-01T16:38:12.246459Z f3a1884 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

React Doctor found no new issues. 🎉

Reviewed by React Doctor for commit f3a1884.

@aXenDeveloper aXenDeveloper changed the title Run JavaScript and declarations watchers in single process perf: Run JavaScript and declarations watchers in single process Dec 1, 2026
@github-actions github-actions Bot added the 🚀 Performerce Improves performance label Dec 1, 2026
`tsc --watch` holds a whole TypeScript program per plugin package and is the
largest part of what `pnpm dev` keeps in memory. `vitnode dev --no-typecheck`,
or `VITNODE_DEV_TYPECHECK=0` for every package a workspace starts, leaves it
out; tsdown still writes the JavaScript and the declarations, and
`vitnode build` keeps type checking.

Measured over the six package watchers in this repository: steady RAM
6.4 GB -> 2.8 GB, startup peak 8.3 GB -> 4.7 GB.

- turbo.json (root and the create-vitnode-app template) passes the variable
  through to the `dev` task.
- The two tsdown watchers only share a runner process when the installed
  TypeScript compiles natively (>= 7); TypeScript 6 keeps a process each, so
  its in-thread compiler cannot hold back JavaScript rebuilds.
- Docs: CLI dev page, plugin build page, contribution guide and READMEs.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CnAiFa6kGTMFMW42Wy4HFj
`pnpm dev` runs `build:scripts` first, which ended in `pnpm i`. The `vitnode`
bin points at the committed `packages/api/cli.mjs`, so pnpm links it on the
first install whether or not `dist/scripts` exists yet - the reinstall only
added start-up time.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CnAiFa6kGTMFMW42Wy4HFj
… lint

The nine `*.postgres.test.ts` files only ran with
`VITNODE_TEST_POSTGRES_URL` set and skipped everywhere else, CI included.
They and their `tests/postgres.ts` helper are gone; AGENTS.md now says tests
never need a running service.

With nothing external left, `test` and `lint` are cacheable: both depend on
`^build:plugins` (they read their dependencies' `dist`), so a change in a
dependency invalidates them and an unchanged package is replayed from cache.
The CI lint step passes `--only`, as the test step already did, because the
packages are built by an earlier job and downloaded.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CnAiFa6kGTMFMW42Wy4HFj
…gram

A package build ran two full TypeScript programs over the same files: tsdown
emitting the declarations and `tsc --noEmit` checking the types. `tsc` now
does both, and tsdown only writes the JavaScript.

`tsc` emits into a staging folder under `node_modules/.cache/vitnode`, kept
between runs with its incremental build info. The CLI copies what changed
into `dist/src`, rewriting `@/` aliases and extensionless imports to the
relative `.js` path of the compiled module and pointing declaration maps back
at the sources - what tsdown's declaration step did before.

- `vitnode build`: one `tsc` (check + emit) next to tsdown.
- `vitnode dev`: `tsc --watch` checks and emits; the package watcher copies.
- `vitnode dev --no-typecheck`: the watcher runs a short `tsc --noCheck`
  after each save, so no TypeScript program stays in memory.

Measured on @vitnode/core (1538 modules): build 16 s / 3.9 GB -> 10 s /
2.8 GB cold, 2.8 s / 1.1 GB with a warm cache; declarations after a save
12-23 s -> ~1 s (3 s without type checking). Six package watchers:
6.4 GB -> 4.4 GB steady, 2.8 GB -> 2.0 GB without type checking.

The TypeScript 6 fallback of two runner processes is gone with the in-thread
declaration build it protected.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CnAiFa6kGTMFMW42Wy4HFj
…ation step

- `@inquirer/prompts` and `ora` are replaced by `@clack/prompts`, which covers
  prompts and the spinner. Questions, defaults, validation and the
  non-interactive flags are unchanged; Ctrl+C, Esc and a closed stdin all end
  the setup with the same goodbye and exit code 0.
- Creating a project no longer runs `vitnode migrate --generate` after
  installing. The generated `dev` script runs `vitnode db:prepare`, which
  generates and applies migrations on first start, so the step only made
  creation slower.
- Removed what nothing used: `@types/prompts` and the `prepare` script, which
  only checked that a committed folder exists.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CnAiFa6kGTMFMW42Wy4HFj
…tsc-alias

`vitnode build` in an API app ran `tsc` and then `tsc-alias` over its output
to rewrite the `@/` imports. tsdown resolves the aliases while it compiles,
so one pass writes `dist` (one file per module, `dist/index.js` as before)
and `tsc --noEmit` checks the types next to it. JSX is compiled with React's
automatic runtime, and `dist` is emptied first so deleted sources leave
nothing behind.

`apps/api` and the create-vitnode-app template depend on `tsdown` instead of
`tsc-alias` (Bun API apps need neither).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CnAiFa6kGTMFMW42Wy4HFj
… dev

The generated root `dev` script ran Turborepo three times in a row:
`turbo build:plugins && turbo db:prepare && turbo dev`. It is now `turbo dev`,
and the order lives in `turbo.json`: every `dev` task depends on
`^build:plugins` and on the `db:prepare` of the package that owns the schema
(`api#db:prepare`, or `web#db:prepare` for a single app).

Naming the owner's task keeps the bootstrap one sequence point for the whole
workspace - the web app of a split deployment still waits for the API's
migrations - which a bare `db:prepare` would not.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CnAiFa6kGTMFMW42Wy4HFj

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cc52277b10

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +509 to +512
const watcher: FSWatcher = watch(
emit ? join(root, "src") : staging,
{ recursive: true },
schedule,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Watch declaration inputs outside src in no-typecheck mode

With --no-typecheck or VITNODE_DEV_TYPECHECK=0, declaration emission only reruns for changes under src, although generated plugin tsconfigs also include types and global.d.ts, and inferred exports can depend on other workspace packages' declarations. Changes to those inputs therefore leave consumers reading stale types until a source file is touched or development restarts. I reproduced this by changing an ambient registry property's literal type: the exported function's declaration retained the old return type until src/registry.ts was touched. Watch the compiler's dependency inputs as well so disabling diagnostics does not stop declaration updates.

Useful? React with 👍 / 👎.

…lient chunks

The client build merged React into the entry chunk and ProseMirror, Tiptap's
core and the emoji data of `@tiptap/extension-emoji` into one 743 kB chunk.
The `vitnode()` Vite plugin now declares code splitting groups for them:

- entry: 358 kB -> 150 kB, with React in a 218 kB chunk that survives deploys
- editor: 743 kB -> prosemirror 219 kB, tiptap 159 kB, editor-emoji 514 kB

Only the grouping of modules into files changes. `editor-emoji` is a single
data set and stays above the report's 500 kB warning.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CnAiFa6kGTMFMW42Wy4HFj

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🚀 Performerce Improves performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants