[Feature] Ship a bundled build (esbuild/tsup) instead of 552 loose files: about 4x faster startup in A/B tests
Description
The TUI loads 1,457 separate files at startup. A CPU profile of the import shows the time is almost entirely file-system work (stat, lstat, open, package.json scope lookups), not JavaScript. Every file is another round trip on an HDD, a network drive or an antivirus-scanned disk. module.enableCompileCache() (source/cli.tsx:20) does not help because compilation is not the cost.
Environment
- OS: Windows 11 (10.0.26300), host heavily loaded
- Node version: 22.22.3
- Nanocoder version: 1.31.0 (main at 5c2e6935)
Evidence
- CPU profile of
import('ink')+import('dist/app/index.js')(4.4 s sampled): 2.48 s(native)+ 1.55 snode:internal(internalModuleStat,getPackageScopeConfig,lstat,open) vs under 0.3 s of JavaScript across all packages. - Alternating A/B, 7 rounds, esbuild bundle (ESM, code splitting, native modules external, no minify) vs
tscoutput: TUI import min 1,206 ms vs 5,129 ms;--plainmin 974 ms vs 3,742 ms. Medians under heavy host load were 3.5 s vs 18.7 s and 3.1 s vs 20.9 s. - The bundle ran
--versionand a complete--plain runagainst a mock model. The full TUI was not run from the bundle, only imported. - Compile cache check: with
NODE_COMPILE_CACHEpopulated (8.3 MB, 1,456 entries) import time did not change. - Externals needed:
tiktoken(wasm),@vscode/ripgrep(binary path),@napi-rs/*(native),react-devtools-core. Output was 227 files, 15.4 MB, before minification.
Proposed Change
- Prototype
esbuild(already a transitive dependency): ESM,splitting: true,platform: node. Keep dynamicimport()boundaries as chunks so lazy features stay lazy. - Keep native and asset-reading packages external and in
dependencies. - Check runtime reads of
../source/app/prompts/sections,source/config/themes.json,dist/voice/andschemas/still resolve. - Decide how to handle pnpm patches (the Ink patch is baked into the bundle) and source maps.
- Alternatives:
tsup,rolldown.
Expected Behavior
- The TUI reaches idle at least 2x faster than main on the same machine (alternating runs, min of 7).
--plain run,/lsp,/model,fetch_url(get-md) and the voice plugin still work from the published tarball.npm packsize and file count are reported in the PR.
Additional Context
- Effort: L. Start with
package.json(build script),source/cli.tsx,tsconfig.json,scripts/. - Risks: packaging, patches, ESM/CJS interop, stack traces without maps. Needs
RELEASE-SMOKE-TEST.mdand the VS Code extension build checked. Treat as a proposal that needs maintainer sign-off. - Combine with the lazy-load issues for the best result.
Issue triage: possible duplicate of #892
@addyCooks — this looks like it covers the same ground as #892 (open): [Feature] Single-file CLI Bundle with Rolldown.
This is the same underlying proposal as #892: replace the per-file tsc output with a single bundler to cut CLI cold-start time, with rolldown listed as an alternative in both directions. Please continue the discussion there so the maintainers can pick one bundler and one approach instead of two parallel efforts.
Filed by a maintainer, so this will not be closed automatically.
Automated issue triage. It flags; it never closes on first sight. A maintainer can remove the label to dismiss this.