Skip to content

🤖 perf: keep the Markdown stack in the workspace page chunk - #6428

Merged
ThomasK33 merged 2 commits into
mainfrom
perf/6334-markdown-chunk
Oct 14, 2026
Merged

ThomasK33 merged 2 commits into
mainfrom
perf/6334-markdown-chunk

Conversation

@ThomasK33

Copy link
Copy Markdown
Member

Summary

Keeps the Markdown stack in the workspace page's chunk again. The seeded workspace page loads 20,079 B less brotli JS (one page chunk instead of two), opening Settings loads 199,950 B less, and first-load JS is unchanged (−148 B). Refs #6334.

Background

Since #6334, MemoryFileEditor imports MarkdownFilePreview statically, so Settings (SettingsPage -> MemorySection -> MemoryBrowser -> MemoryFileEditor) needs the Markdown stack. Rollup groups modules by the lazy entries that need them. With two lazy importers (the workspace page and Settings), it moved the stack out of the page chunk into a shared chunk. The raw JS the seeded page loads did not change, but two files compress worse than one: the 1.83 MB page chunk became AIView-*.js + mermaid-LQXJBOYN-*.js. The Lighthouse mobile load is bandwidth-bound; same-session A/Bs put #6334 at +79 to +119 ms simulated LCP.

Implementation

  • MemoryFileEditor lazy-loads the preview through the AIView entry module: React.lazy(() => import("@/browser/components/AIView/AIView")), inside LazyFeature. AIView.tsx re-exports MarkdownFilePreview. Every importer of the stack then goes through one entry, so Rollup keeps one chunk.
  • A guard test (markdownStack.importGraph.test.ts) walks the static import graph of App.tsx, SettingsPage, ProjectPage, ScratchPage and AnalyticsDashboard, and fails if any reaches MarkdownRenderer/MarkdownFilePreview. It fails on main with the 🤖 feat: render Markdown memory files and AGENTS.md #6334 chain. Mutation caught: re-adding a static MarkdownFilePreview import to MemoryFileEditor fails it.
  • AppEarlyPageImport.test.tsx mocks the AIView module, and Bun keeps that mock for later suites despite its afterAll restore. The mock now returns the real MarkdownFilePreview, or the MemoryTab preview tests fail when both files run in one process.

Options measured (renderer builds of 79e5be2, brotli bytes)

Option Seeded page br vs no-split reference First-load br Settings beyond first load br
main 1,410,453 +19,986 461,989 342,377
No-split reference (preview import stubbed) 1,390,467 0 462,162 142,180
A: React.lazy(import(MarkdownFilePreview)) 1,411,563 +21,096 (still split) 461,992 142,440
B: manualChunks for AIView + MarkdownRenderer 1,439,120 +28,653 1,111,230 108,625
C: lazy import through the AIView entry (this PR) 1,390,185 −282 462,044 142,792

A fails because the lazy preview is one more entry that shares the stack. B fails because Rollup 4 pulls every static dependency of a manual chunk's modules (react…) into it, and main then imports it.

Accepted cost: cold preview in Settings

In browser mode, a Markdown preview in Settings opened before any workspace visit fetches the page chunk on click (~567 KB br, 8 files). This is accepted: opening Settings gets ~200 KB br lighter for everyone, desktop preloads AIView at idle (appShellRef), and on a workspace route the chunk is already loaded. While it loads, the preview box (min height kept) is empty; a failed load shows LazyFeature's Reload message.

Validation

Gates on one clean build pair, merge base 2ce183d vs head (each make build-renderer under the shared measurement lock):

Gate Merge base Head Result
a. Seeded page br (page chunks) 1,411,252 (AIView + mermaid-LQXJBOYN) 1,391,173 (mermaid-LQXJBOYN only) −20,079; reference on this base ≈ 1,391,266 (base − 19,986), head −93
b. First-load JS br 462,330 462,182 −148
c. Settings beyond first load br 342,576 142,626 −199,950
d. make check-react-compiler 23/24 hot components compile (1 known skipped) pass
d. make static-check exit 0 pass
d. make crap-check PASS, 0 violations, CC 47 -> 47 pass
e. Dogfood xum server (env -i, telemetry off, 127.0.0.1, temp XUM_ROOT, --no-auth) both flows render the preview pass

Gate e flows (screenshots in a comment below): (1) workspace -> right-sidebar Memory tab -> Markdown memory file -> Edit -> Preview; (2) fresh page load straight to /settings/memory -> open the file in Preview. In flow 2, performance resources showed SettingsPage + MemoryBrowser only, and mermaid-LQXJBOYN-*.js arrived after opening the file.

Lighthouse VM A/B: not run here; the perf owner runs it.

Risks

Low. Only the Memory editor's preview changes: it now mounts behind Suspense. Worst case is an empty preview box while the chunk loads, or a Reload message if the chunk fails to load.


Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high • Cost: $3.44

…statically

Fails on main: SettingsPage -> MemorySection -> MemoryBrowser -> MemoryFileEditor -> MarkdownFilePreview (#6334).
Keeps the Markdown stack in the workspace page's chunk (#6334 split it in two).
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T23:20:07.369004Z e40285a Manual request
🔒 Security Review ✅ Completed 2026-10-13T23:20:42.859514Z e40285a Manual request
ℹ️ 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.

@ThomasK33

Copy link
Copy Markdown
Member Author

Dogfood screenshots (head e40285a, xum server under env -i, XUM_DISABLE_TELEMETRY=1, 127.0.0.1, temp XUM_ROOT, --no-auth).

Flow 1: workspace -> right-sidebar Memory tab -> notes.md -> Edit -> Preview

Desktop (1440 px):

Workspace Memory tab preview, desktop

Phone (390 px, sidebar full-screen):

Workspace Memory tab preview, 390 px

Flow 2: fresh page load straight to /settings/memory -> open notes.md (Preview)

Before the click, the page had loaded only SettingsPage + MemoryBrowser of the relevant chunks; mermaid-LQXJBOYN-*.js (the page chunk) arrived after opening the file.

Desktop (1440 px):

Settings Memory preview after a fresh load, desktop

Phone (390 px):

Settings Memory preview after a fresh load, 390 px

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: e40285acf3

ℹ️ 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".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: e40285acf3

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@ThomasK33

Copy link
Copy Markdown
Member Author

Perf owner: ready to merge at e40285acf3.

Lighthouse A/B on the dedicated VM (tk/lh-bench), seeded workspace page, base = merge base 2ce183de8c, head = e40285acf3, 6+6 runs per preset in one session, all 24 host checks per folder quiet. Statistic: the mean of the 3 highest simulated LCPs of 6 runs. On identical builds this statistic moved at most 21 ms within a session.

Preset Base Head Change Rule (declared before the run)
mobile 9,501.7 ms 9,372.7 ms −129.0 ms pass: head ≤ base + 50
desktop 1,815.0 ms 1,787.7 ms −27.3 ms pass: head ≤ base + 50

Mobile performance score medians stay at 59 on both arms, and desktop at 92 on both. The predicted change was about −80 ms mobile and −20 ms desktop (#6334 measured +79 to +119 ms mobile).

Other gates (lane, one build pair): workspace-page JS 1,411,252 → 1,391,173 B brotli (one page chunk again), first-load −148 B, Settings beyond first load −199,950 B, React Compiler 23/24, make static-check and make crap-check pass, and the dogfood screenshots above. Codex: one round, clean on this head. 0 open threads. Required passes.

The 3 Pixel snapshots are not a required check. They come from the Memory editor's preview, which now loads lazily. Local Storybook shows base and head the same.


Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high

@ThomasK33
ThomasK33 added this pull request to the merge queue Oct 13, 2026
Merged via the queue into main with commit c5e9c46 Oct 14, 2026
61 of 64 checks passed
@ThomasK33
ThomasK33 deleted the perf/6334-markdown-chunk branch October 14, 2026 00:04
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