Skip to content

perf(web): reduce startup bundle pressure for optional runtimes#746

Merged
limityan merged 2 commits into
GCWing:mainfrom
limityan:yanzhn/web-ui-bundle-p4
May 16, 2026
Merged

perf(web): reduce startup bundle pressure for optional runtimes#746
limityan merged 2 commits into
GCWing:mainfrom
limityan:yanzhn/web-ui-bundle-p4

Conversation

@limityan
Copy link
Copy Markdown
Collaborator

@limityan limityan commented May 16, 2026

Summary

This PR contains the completed stage 0-4 Web UI startup bundle optimization work, squashed into two commits and without the design document.

It keeps chunkSizeWarningLimit unchanged and focuses on removing accidental startup dependencies rather than hiding the warning.

Optimization Plan

  • Add repeatable bundle measurement guardrails:
    • scripts/report-web-bundle-size.cjs reports raw and gzip sizes from dist/assets.
    • scripts/report-web-main-static-graph.cjs reports the main.tsx static graph and can assert that optional runtimes stay unreachable from startup.
  • Narrow startup tool initialization:
    • main.tsx now imports ./tools/initializeTools instead of the full ./tools barrel.
    • Git and LSP initialization moved behind narrow initializer modules while keeping existing barrels compatible.
  • Replace dynamic Lucide namespace lookups:
    • Context menu, MiniApp icons, and smart recommendations now use explicit icon maps.
    • Existing fallback behavior is preserved for unknown icon names.
  • Defer optional Markdown runtimes:
    • Mermaid loads through a cached dynamic import in MermaidService only when Mermaid content needs rendering, validation, or export.
    • Markdown code blocks and CodePreview use a shared async Prism loader.
    • Code content remains readable before Prism finishes loading, so normal chat and plain Markdown rendering do not wait for syntax highlighting.

Optimization Results

Measured from the stage 0 baseline to the final stage 4 build:

  • Largest entry JS: 9953.0 KiB raw / 2802.0 KiB gzip -> 8242.6 KiB raw / 2286.1 KiB gzip.
  • Entry JS reduction: -1710.4 KiB raw / -515.9 KiB gzip.
  • main.tsx static graph: 1067 -> 1013 local modules.
  • Total JS/CSS raw size: 14332.4 KiB -> 13952.4 KiB.
  • Total JS/CSS gzip size: 3905.1 KiB -> 3930.0 KiB.
    • The small gzip increase is an intentional experience tradeoff from async Prism language assets: code blocks stay readable first, then enhance, while normal startup no longer prepays the syntax highlighter runtime.
  • Static graph assertions confirm startup no longer reaches mermaid or react-syntax-highlighter, and main.tsx no longer imports ./tools directly.
  • dist/index.html does not preload mermaid, prism, or react-syntax assets.

Experience Protection

  • Did not lazy-load the whole SessionScene or the whole Markdown renderer.
  • Git/LSP startup remains after-render initialization through narrower imports.
  • Mermaid and code highlighting are optional enhancements, not blockers for plain chat or plain Markdown.
  • Unknown icon names keep fallback UI behavior instead of rendering blank controls.

Verification

  • pnpm run lint:web
  • pnpm run type-check:web
  • pnpm --dir src/web-ui run test:run
  • pnpm --dir src/web-ui run build
  • pnpm run verify:monaco-assets
  • node scripts/report-web-bundle-size.cjs --top=20
  • node scripts/report-web-main-static-graph.cjs --assert-external-unreachable=react-syntax-highlighter --assert-external-unreachable=mermaid --assert-no-direct-import=src/web-ui/src/main.tsx:./tools --top=15
  • Select-String -Path dist\index.html -Pattern 'mermaid|prism|react-syntax'
  • git diff --check upstream/main..HEAD

limityan added 2 commits May 16, 2026 09:11
Add repeatable Web UI bundle-size and main-entry static graph reporters for the staged startup optimization work.

The graph reporter supports dependency reachability and direct-import assertions, so future changes can verify that optional runtimes stay out of the startup path without changing Vite warning thresholds.
Route startup tool initialization through narrow Git and LSP entry points so main.tsx no longer imports the full tools barrel.

Replace lucide namespace lookups with explicit icon maps while keeping fallback behavior for unknown icons.

Defer Mermaid and Prism syntax highlighting to cached async loaders, keeping plain Markdown and code fallback rendering available before optional runtimes load.
@limityan limityan force-pushed the yanzhn/web-ui-bundle-p4 branch from b3fd568 to ba5c8cd Compare May 16, 2026 01:19
@limityan limityan changed the title perf(web): defer editor and terminal startup runtime perf(web): reduce startup bundle pressure for optional runtimes May 16, 2026
@limityan limityan changed the base branch from yanzhn/web-ui-bundle-p2 to main May 16, 2026 01:20
@limityan limityan marked this pull request as ready for review May 16, 2026 01:20
@limityan limityan merged commit 413c515 into GCWing:main May 16, 2026
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.

1 participant