Skip to content

perf(web): split heavy chat chunks and group startup bundles - #1096

Open
badcuban wants to merge 2 commits into
chore/perf-apps-performance-auditfrom
perf/split-chat-web-chunks
Open

badcuban wants to merge 2 commits into
chore/perf-apps-performance-auditfrom
perf/split-chat-web-chunks

Conversation

@badcuban

Copy link
Copy Markdown
Collaborator

Stacked on #1095.

Opening a chat thread eagerly downloaded and parsed 198 static JS files (5,723 KB raw, 1,814 KB gzipped), including @pierre/diffs, the VS Code file icon catalog, the GitHub HTML sanitizer, and closed-by-default panels and dialogs. App startup alone also loaded 96 separate files with 70 small chunks under 5 KB.

What changed

  • Decoupled @pierre/diffs (447 KB) from chat startup, queued custom code theme registrations until Pierre loads, cleared rejected import promises so transient failures recover, and gated highlighter warm-up on fenced code blocks so prose-only chats skip loading it.
  • Moved the VS Code file icon catalog (278 KB) behind an on-demand loader with same-size generic icon fallbacks and online retry recovery.
  • Split the GitHub HTML markdown sanitizer (159 KB) out of standard chat markdown and folded message previews, suppressing raw HTML fallback text while the sanitizer chunk loads.
  • Split Find in chat indexing out of initial chat load while keeping the Find bar input, focus capture, and Escape handling eager so Cmd/Ctrl+F never leaks keystrokes into the composer.
  • Lazy-loaded closed-by-default side panels and dialogs (Source Control, Agents, Project Board, Browser preview, Theme Picker, PR Thread dialog, File Preview dialog, and scheduled task timeline rows), preserving Escape cancellation during load and reserving row height for schedule lines.
  • Added zero-leakage Rolldown codeSplitting groups in apps/web/vite.config.ts for initial React, Effect, TanStack, UI, contracts, and shared startup modules.
  • Updated one assertion in apps/web/src/components/ChatView.panels.browser.tsx to wait for the lazy Source Control panel body after clicking its tab, matching the existing waits in the same test.

Before and after bundle size

Measured from production builds of chore/perf-apps-performance-audit versus this branch by tracing the exact static JS import graph for each screen.

Screen Before After Change
App startup 96 files, 2,601 KB raw (835 KB gzipped) 8 files, 2,636 KB raw (806 KB gzipped) 92% fewer files, -29 KB gzipped
Opening a chat thread 198 files, 5,723 KB raw (1,814 KB gzipped) 109 files, 4,780 KB raw (1,514 KB gzipped) -942 KB raw (-16.5%), -300 KB gzipped (-16.5%), 45% fewer files
Opening a new draft 193 files, 5,609 KB raw (1,776 KB gzipped) 106 files, 4,751 KB raw (1,503 KB gzipped) -859 KB raw (-15.3%), -273 KB gzipped (-15.4%), 45% fewer files
Opening Settings 182 files, 3,434 KB raw (1,135 KB gzipped) 99 files, 3,463 KB raw (1,104 KB gzipped) 46% fewer files, -31 KB gzipped

Verification

  • vp fmt, vp lint, and vp run typecheck (14/14 packages)
  • vp run --cache '@threadlines/web#test' (273 test files, 3,408 tests)
  • vp run --cache '@threadlines/web#test:browser' (118 test files, 1,215 tests)
  • vp run '@threadlines/web#build'

Opening a chat thread eagerly downloaded and parsed 198 static JS files (5,723 KB raw, 1,814 KB gzipped), including `@pierre/diffs`, the VS Code file icon catalog, the GitHub HTML sanitizer, and panels and dialogs that start closed. Startup alone also pulled 96 separate files with 70 small chunks under 5 KB.

This splits those features behind on-demand imports and groups stable initial libraries in Vite/Rolldown without pulling lazy code into startup:

- Decouple `@pierre/diffs` from initial chat load, queue custom theme registrations until Pierre loads, recover from failed imports, and gate highlighter warm-up on fenced code blocks.
- Load the VS Code file icon manifest on demand with a same-size fallback icon and reconnect retry.
- Load the GitHub HTML markdown renderer only for GitHub HTML documents, and keep Find in chat indexing lazy while keeping the Find bar input, focus capture, and Escape handling eager.
- Lazy-load closed-by-default side panels, dialogs, the theme picker, and scheduled task timeline lines, preserving Escape cancellation while chunks load and reserving row height for schedule lines.
- Group initial React, Effect, TanStack, UI, contracts, and shared startup code in `apps/web/vite.config.ts`.

This cuts initial chat thread JS by 942 KB raw (300 KB gzipped, -16.5%) and 45% fewer files, and drops app startup from 96 files to 8 files (-29 KB gzipped).
@vercel

vercel Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
threadlines Skipped Skipped Nov 25, 2026 6:19am UTC

Request Review

…-web-chunks

# Conflicts:
#	apps/web/src/components/ChatView.tsx

This branch was previously deployed

1 inactive deployment
Preview — 63f3325a Deployed Nov 25, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant