Priority: P2
Category: performance, cli
Parent: #3011
Depends on: Lazy load heavy optional dependencies sub-issue (creates the import() split points)
Problem / 问题
Single monolithic dist/cli.js bundle forces V8 to parse all code at startup. V8 gives up lazy parsing for very large files, making startup slower. All optional subsystems (OTel, LSP, code highlighting, channels) are inlined.
单体 dist/cli.js 迫使 V8 在启动时解析所有代码。超大文件导致 V8 放弃懒解析。所有可选子系统被内联。
Proposed Solution / 方案
Enable esbuild code splitting:
- Prior sub-issue's
import() calls automatically create split points
- Configure esbuild with
splitting: true, format: 'esm'
- Verify chunks load correctly from
dist/ directory
Expected split chunks:
- Main entry (
cli.js) — core runtime only
chunk-otel.js — OpenTelemetry SDK + exporters
chunk-highlight.js — highlight.js/lowlight
chunk-lsp.js — LSP subsystem
chunk-channels.js — channel packages
Reference: Claude Code uses Bun bundle with automatic code splitting via dynamic import().
Acceptance Criteria / 验收标准
Problem / 问题
Single monolithic
dist/cli.jsbundle forces V8 to parse all code at startup. V8 gives up lazy parsing for very large files, making startup slower. All optional subsystems (OTel, LSP, code highlighting, channels) are inlined.单体
dist/cli.js迫使 V8 在启动时解析所有代码。超大文件导致 V8 放弃懒解析。所有可选子系统被内联。Proposed Solution / 方案
Enable esbuild code splitting:
import()calls automatically create split pointssplitting: true, format: 'esm'dist/directoryExpected split chunks:
cli.js) — core runtime onlychunk-otel.js— OpenTelemetry SDK + exporterschunk-highlight.js— highlight.js/lowlightchunk-lsp.js— LSP subsystemchunk-channels.js— channel packagesReference: Claude Code uses Bun bundle with automatic code splitting via dynamic
import().Acceptance Criteria / 验收标准
dist/cli.jsreduced in size (main entry only)npm packincludes all chunks