Skip to content

perf(site): stop loading monaco on every page - #31367

Draft
mafredri wants to merge 5 commits into
perf/chat-focus-withinfrom
perf/site-monaco-chunk
Draft

mafredri wants to merge 5 commits into
perf/chat-focus-withinfrom
perf/site-monaco-chunk

Conversation

@mafredri

@mafredri mafredri commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Base: #31366 (perf/chat-focus-within). Fourth of five stacked fixes.

Every page imports and executes monaco's 4.5 MB chunk, its stylesheet with 18 A:focus-within B rules, and the 807 KB emoji-picker chunk. Vite 8 codeSplitting.groups also take the modules their matches import that no earlier group took: the monaco group, listed first, takes React and Vite's preload helper, which the entry imports, and the emoji-picker group (/frimousse|emojibase-data/), listed ahead of radix-ui, takes React's JSX runtime. This PR deletes the monaco, xterm and emoji-picker groups, so index.html loads neither chunk. The three libraries stay lazy but lose stable vendor chunk names; monaco now ships in editor.api-*.js and editor-*.css.

Builds below predate #31663 and have monaco 0.55.1, with 4 such rules. Production builds of the pre-rebase versions of 30d26d37dd (base) and eff8991039 (this PR): the JS index.html loads up front falls from 6,987,293 to 2,794,832 bytes without monaco's chunk and stylesheet, and neither build has a static import cycle between chunks.

On the pre-rebase version of eff8991039, the template files, version and editor pages rendered monaco without errors, loaded directly in Chromium and WebKit and after in-app navigation in Chromium. Vite never removes a lazy chunk's stylesheet, so after one of those pages loads, monaco's rules apply until reload.

#31278 bench (a tool, not for merging) on the pre-rebase version of c5a25907e6 (base) and this PR on it, before later commits, which keep the selector kinds: 2 long chats, 140k nodes, 3 alternating runs; this measures the whole chunk, not its rules alone, and this PR does not explain the remaining 205 to 242 ms of WebKit focus time.

idle focus, pointer p50 base this PR
WebKit 574 to 670 ms 205 to 242 ms
Chromium (within noise) 10 to 11 ms 10 to 13 ms

🤖 This PR was created with the help of Coder Agents, and will be reviewed by a human. 🏂🏻

@mafredri

This comment has been minimized.

@coder-agents-review

coder-agents-review Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Chat: Review posted | View chat
Requested: 2026-10-27 20:40 UTC by @mafredri

Review history
  • R1 (2026-10-27): 9 reviewers, 3 P3, 1 P4, COMMENT. Review
  • R2 (2026-10-27): 8 reviewers, 3 P3, 2 P4, COMMENT. Review
  • R3 (2026-10-27): 4 reviewers, 3 P3, 2 P4, APPROVE. Review

deep-review v0.13.0 | Round 3 | 4f40017..d18c1b2

Last posted: Round 3, 5 findings (3 P3, 2 P4), APPROVE. Review

Finding inventory

Findings

# Sev Status Location Summary Round Reviewer Posted
CRF-1 P3 Author contested; panel closed R2 (1/1 accept) site/vite.config.mts:76 No check fails when a lazy library returns to the up-front chunks R1 Netero Yes
CRF-2 Note Note (body) site/vite.config.mts:79 radix-ui group also captures React; comment does not say why it is safe R1 Netero No
CRF-3 P3 Author fixed (d18c1b2) site/vite.config.mts:78 Comment blames React, but a narrow monaco group still goes eager via Vite's preload helper R1 Pariston P3, Razor P3, Leorio P3/P4, Gon Note, Ging-TS Note, Mafu-san Note Yes
CRF-4 P3 Author accepted R2 (PR limits cost to tabs that opened a monaco page; remaining cost moved out of scope by Killua, needs human decision) site/vite.config.mts:79 Monaco stylesheet stays applied after any template editor visit; residual WebKit cost unmeasured R1 Killua Yes
CRF-5 P4 Author fixed (PR description, cites 4f40017 and c27ea03) site/vite.config.mts:76 Bench and manual-test SHAs in description are not reachable or not named R1 Leorio P4, Mafu-san Note Yes
CRF-6 Note Note (body) site/vite.config.mts:79 Monaco language modes now load per language instead of in one chunk R1 Killua No
CRF-7 OOS Out of scope (body) site/src/pages/AgentsPage/AgentChatPage/AgentChatPageView.tsx:50 Static TerminalPanel import loads xterm on every agent chat page R1 Nami No
CRF-8 Note Dropped by orchestrator (informational, no action; confirms rule) site/vite.config.mts:76 Tightened xterm/emoji-mart groups stayed lazy in experiment R1 Razor No
CRF-9 Note Dropped by orchestrator (informational, confirms comment against rolldown docs) site/vite.config.mts:76 includeDependenciesRecursively default true matches comment R1 Nami No
CRF-10 P4 Author contested; panel closed R3 (1/1 accept) site/vite.config.mts:76 Comment and description omit why groups were deleted instead of using includeDependenciesRecursively: false R2 Leorio Yes
CRF-11 OOS Out of scope (body) site/package.json:16 No build-output check exists; a lazy-library group passes CI (CRF-1 consequence) R2 Netero No
CRF-12 OOS Out of scope (body) site/src/components/SyntaxHighlighter/SyntaxHighlighter.tsx:3 monaco's 4 :focus-within rules stay applied after a monaco page until reload (CRF-4 remainder) R2 Killua No

Contested and acknowledged

CRF-10 (P4, site/vite.config.mts:76) - Comment omits why groups were deleted instead of using includeDependenciesRecursively: false

  • Finding: Neither the comment above groups nor the PR description says why the lazy groups were deleted instead of kept with includeDependenciesRecursively: false (tried in 8204a25ee0). The reason is only in 169c9cc545's body, which the squash merge drops; Rolldown recommends strictExecutionOrder: true with that option to avoid invalid chunks. Proposed appending one comment line.
  • Author defense (R3, PRRC_kwDOGkVX1s8AAAABBeWEzg): includeDependenciesRecursively: false also keeps monaco out of the up-front chunks (a build of 8204a25's config loads 2,794,844 bytes up front against this PR's 2,794,832, with no import cycles), so a developer who reaches for it does not bring the regression back. Rolldown's doc comment on that option states the strictExecutionOrder pairing where they would set it.
  • Panel closure (R3, 1/1): Leorio, the agent that raised it (reused from R2), accepted: the finding assumed the option was a path back to the regression; the author's measurement shows it keeps monaco lazy, and the strictExecutionOrder warning is in Rolldown's doc comment on the option (define-config-BLptERXo.d.mts:1224-1236), which the developer sees where they set it.

CRF-1 (P3, site/vite.config.mts:76) - No check fails when a lazy library returns to the up-front chunks

  • Finding: No build check or test fails when monaco, xterm or emoji-mart returns to the chunks index.html loads up front; the chore(site): upgrade to Vite 8 #23485 regression passed CI. Proposed a post-build check that fails when a chunk index.html references contains monaco-editor, @xterm or emoji-mart code.
  • Author defense (R2, PRRC_kwDOGkVX1s8AAAABBd-U8w): A check that reads site/out after the build is new CI tooling, and this PR only deletes the groups. The comment above groups states why a lazily loaded library must not get one.

CRF-4 (P3, site/vite.config.mts:79) - Monaco stylesheet stays applied after any template editor visit

  • Finding: After a tab opens a template files, version or editor page, monaco's editor-*.css (4 :focus-within descendant rules) stays applied until reload, so the WebKit focus cost may return for that tab. Proposed measuring it and, if it returns, scoping or removing those rules in this PR, or a human ticket/acceptance.
  • Author acknowledgment (R2, PRRC_kwDOGkVX1s8AAAABBd-YBQ): The cost does return: on an earlier 60k-node page, deleting monaco's 4 rules after the 3 attachment rules cut WebKit idle focus from 145 to 12 ms. On main every tab pays it from the first page; this PR leaves it only in tabs that opened a monaco page, as the description states. Scoping monaco's rules is a separate change. No ticket linked.
  • Panel closure (R2, 1/1): Killua, the agent that raised it (reused from R1), accepted: the PR reduces how many tabs pay the cost and adds no regression; the remaining cost comes from monaco's stylesheet, which the diff does not add or change, so it is out of scope (CRF-12). No ticket; needs a human decision.

CRF-1 panel closure

  • Panel closure (R2, 1/1): Netero, the agent that raised it (reused from R1), accepted: no build-output check exists anywhere in the repository (git grep for size-limit/bundlesize/chunkSizeWarning empty; no lint script reads build output), and the PR adds no code path a test could cover. Listed as out of scope (CRF-11) for a human decision.

Round log

Round 1

Netero: 1 P3, 1 Note. No P0, panel proceeds. Law not run (effective additions 4).
Round type: round 1, full panel. Focused (one TS config file). Specialists: killua (bundle/perf), nami (frontend load), ging-ts (.mts). Core: pariston, mafuuu. Pool: gon, leorio, mafu-san (agent-authored, verification claims). Wildcard (random): razor.
Cross-check: Pariston and Razor independently built head with narrow monaco test and saw the 4.18 MB monaco chunk preloaded via Vite's preload helper; empirical result outranks Mafuuu's and Gon's "comment matches docs". Leorio P3 (rejected includeDependenciesRecursively: false alternative missing from description) merged into CRF-3: keep-argument was that squash merge loses the commit-body rationale; merged because CRF-3's fix puts that rationale in the code comment, which survives the squash. Mafu-san emoji-mart reproduction (emoji-mart group alone preloads 558 KB) folded into CRF-3 evidence. CRF-2 kept as body Note; CRF-3's fix covers stating why radix-ui is safe. Mafu-san pre-rebase provenance note folded into CRF-5. Mafuuu: no findings. 3 P3, 1 P4, 2 body Notes, 1 OOS, 2 dropped. Reviewed against b7828d0..0481c20. Event COMMENT.

Round 2

Churn guard PROCEED: CRF-3, CRF-5 addressed; CRF-4 acknowledged; CRF-1 contested. Fix round (only the comment above groups and the PR description changed; rebased onto 4f40017). Netero reused (dispute check-in, CRF-1): accepted, moved to OOS (CRF-11). Panel: pariston, razor (CRF-3 raisers), leorio, gon (comment touched, floor), killua (reused for CRF-4), ging-ts, nami (specialists), wildcard meruem (random). Killua's first output omitted CRF-4; asked it to state a position; it accepted and moved remainder to OOS (CRF-12). CRF-3 verified fixed by Pariston and Razor (narrow monaco group after radix-ui still preloads 4,178,496 bytes) and Netero (emoji-mart group after radix-ui stays lazy). CRF-5 verified fixed by Leorio. New: CRF-10 P4 (Leorio). Keep-argument for Leorio's R1 P3: squash merge drops the rationale in 169c9cc's body. Kept at P4, Leorio's own R2 rating, because Rolldown's doc comment on the option carries the strictExecutionOrder warning where a developer enabling it would read it. This is the Leorio R1 point merged into CRF-3, which the CRF-3 fix did not cover. Reviewed against 4f40017..d18c1b2. Event COMMENT.

Round 3

No new commits (head d18c1b2). Churn guard PROCEED: CRF-10 contested. Fix round. Netero (new agent): no findings. Panel: leorio (reused R2 agent faafee21, dispute check-in on CRF-10), pariston, mafuuu (core, to reach 3), wildcard zoro (random). No files changed since the last panel round, so no domain specialists triggered.
Leorio accepted the CRF-10 defense (closed 1/1). Pariston, Mafuuu, Zoro: no findings. Mafuuu verified the comment's "no earlier group took" against Rolldown's group index tie-break (define-config-BLptERXo.d.mts:1135). No open in-scope findings. Reviewed against 4f40017..d18c1b2. Event APPROVE.

About deep-review

CRF = Coder Review Finding (P0-P4, Nit, Note)

Reviewer Focus
Bisky tests
Chopper ops/errors
Churn-guard change verification
Ging language modernization
Gon naming
Hisoka edge cases
Killua perf
Kite change integrity
Knov contracts
Knuckle SQL
Komugi flake/determinism
Kurapika security
Law decomposition
Leorio docs
Luffy product
Mafu-san process
Mafuuu contracts
Melody dispatch/pairing
Meruem structural
Nami frontend
Netero mechanical checks
Pariston premise testing
Pen-botter product gaps
Razor verification
Robin duplication
Ryosuke Go arch
Takumi concurrency
Zoro shape

🤖 Managed by Coder Agents.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 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-27T20:41:20.644863Z d18c1b2 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.

@chatgpt-codex-connector

This comment has been minimized.

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR deletes the monaco, xterm and emoji-mart codeSplitting groups so index.html no longer loads monaco's chunk and stylesheet up front. Findings: 3 P3, 1 P4. Production builds of the head reproduced the description's 2,794,832 bytes of up-front JS and found no static import cycle.

Out of scope (needs a ticket or explicit acceptance by a human):

  • site/src/pages/AgentsPage/AgentChatPage/AgentChatPageView.tsx:50: TerminalPanel is imported statically, so every agent chat page load downloads and parses the 539,398-byte WorkspaceTerminalAlerts-*.js chunk that contains xterm, even when no terminal tab opens. The base build had the same static edge.

Notes:

  • site/vite.config.mts:79: the remaining radix-ui group also captures React (assets/radix-ui-*.js contains React's react.forward_ref and react.lazy symbols). This is harmless because every page loads radix-ui, but the comment does not say why this group is allowed.
  • site/vite.config.mts:79: without the monaco group, monaco's language modes (hcl, cpp, tsMode, and about 80 others) are separate chunks that load when a file of that language opens, instead of being part of one 4,200,212-byte chunk.

🤖 This review was automatically generated with Coder Agents.

Comment thread site/vite.config.mts Outdated
{ name: "emoji-mart", test: /emoji-mart/ },
{ name: "radix-ui", test: /radix-ui/ },
],
// No groups for lazily loaded libraries (monaco, xterm, emoji-mart): a

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 [CRF-1] No build check or test fails when monaco, xterm or emoji-mart goes back into the chunks index.html loads up front. (Netero)

The monaco group added in #23485 put 4.2 MB on every page and CI passed, and the only guard against a repeat is this comment. git grep finds no script or test that reads site/out/index.html or checks chunk contents. Add a post-build check that fails when a chunk index.html references contains monaco-editor, @xterm or emoji-mart code.

🤖

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left this out: a check that reads site/out after the build is new CI tooling, and this PR only deletes the groups. The comment above groups states why a lazily loaded library must not get one.

🤖 Posted using /amend-review skill via Coder Agents.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted: the repository has no check that reads build output, and this PR adds no code path a test could cover. Moved to the review body as out of scope for a human to file or accept.

🤖

Comment thread site/vite.config.mts Resolved
Comment thread site/vite.config.mts
// No groups for lazily loaded libraries (monaco, xterm, emoji-mart): a
// group also takes every module they import, so a monaco group would
// take React and make every page load monaco.
groups: [{ name: "radix-ui", test: /radix-ui/ }],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 [CRF-4] After a user opens a template files, version or editor page, the tab keeps monaco's stylesheet until reload, so the WebKit focus cost may come back for the rest of that tab's life. (Killua)

The head's editor-Br_kD0ds.css has the same content hash as the base's monaco-Br_kD0ds.css (145,989 bytes, 4 :focus-within descendant rules), and the description states Vite does not remove it. The bench compared the whole monaco chunk, so how much of the 330 ms WebKit difference comes from these 4 rules is unverified. Run the #31278 WebKit bench after loading a template files page in the same tab; if the cost returns, either scope or remove those rules in this PR, or a human needs to file a ticket or accept the gap.

🤖

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cost does return: on an earlier 60k-node page, deleting monaco's 4 rules after the 3 attachment rules cut WebKit idle focus from 145 to 12 ms. On main every tab pays it from the first page; this PR leaves it only in tabs that opened a monaco page, as the description states, and scoping monaco's rules is a separate change.

🤖 Posted using /amend-review skill via Coder Agents.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted: this PR reduces which tabs pay the cost and adds none. The remaining cost comes from monaco's stylesheet, which this diff does not change, so it is in the review body as out of scope for a human to file or accept.

🤖

Comment thread site/vite.config.mts Resolved
@mafredri

This comment has been minimized.

@chatgpt-codex-connector

This comment has been minimized.

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new comment above groups is accurate. Builds of the head with a narrowed monaco group placed after radix-ui still preload the 4,178,496-byte monaco-*.js, and an emoji-mart group after radix-ui stays lazy. Findings: 1 P4.

Addressed since round 1: the comment now names the preload helper and the radix-ui ordering condition, and the description cites 4f40017f24 and c27ea03f2c for every measurement. The build check and monaco's stylesheet are accepted for this PR and listed below.

Out of scope (needs a ticket or explicit acceptance by a human):

  • site/package.json:16: no script or CI job reads the build output, so a future codeSplitting group that puts a lazily loaded library into the chunks index.html loads up front passes CI, as the monaco group from #23485 did.
  • site/src/components/SyntaxHighlighter/SyntaxHighlighter.tsx:3: importing monaco-editor adds its stylesheet with 4 :focus-within descendant rules that stay applied until reload, so after a tab opens a template files, version or editor page, WebKit chat focus changes in that tab cost about 130 ms more on a 60k-node page.

🤖 This review was automatically generated with Coder Agents.

Comment thread site/vite.config.mts
{ name: "emoji-mart", test: /emoji-mart/ },
{ name: "radix-ui", test: /radix-ui/ },
],
// A group also takes the modules its matches import that no earlier group

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P4 [CRF-10] Neither this comment nor the PR description says why the lazy groups were deleted instead of kept with includeDependenciesRecursively: false, which 8204a25ee0 tried first. (Leorio)

The reason is only in the body of 169c9cc545, which the squash merge drops. Rolldown 1.2.14 recommends setting strictExecutionOrder: true with that option "to avoid generating invalid chunks" (rolldown/dist/shared/define-config-BLptERXo.d.mts:1228-1233). A developer who wants a stable monaco-*.js name back will reach for that option first. Append one line, for example: // includeDependenciesRecursively: false avoids this, but Rolldown requires strictExecutionOrder with it to avoid invalid chunks.

🤖

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not added: includeDependenciesRecursively: false also keeps monaco out of the up-front chunks (a build of 8204a25's config loads 2,794,844 bytes up front against this PR's 2,794,832, with no import cycles), so a developer who reaches for it does not bring the regression back. Rolldown's doc comment on that option states the strictExecutionOrder pairing where they would set it.

🤖 Posted using /amend-review skill via Coder Agents.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted: with your measurement, includeDependenciesRecursively: false keeps monaco lazy, and Rolldown's doc comment on that option states the strictExecutionOrder requirement where a developer sets it.

🤖

@mafredri

Copy link
Copy Markdown
Member Author

@codex review
/coder-agents-review

🤖

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: d18c1b21a5

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

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No new commits since round 2, and there are no open findings. The out-of-scope items from rounds 1 and 2 (the missing build-output check, monaco's stylesheet staying applied after a template editor visit, and the static TerminalPanel import on agent chat pages) still need a ticket or explicit acceptance by a human.

🤖 This review was automatically generated with Coder Agents.

@mafredri
mafredri added this pull request to stack #31375 October 27, 2026 21:24
@mafredri
mafredri force-pushed the perf/site-monaco-chunk branch 2 times, most recently from 6aee4a7 to 35d4a61 Compare October 27, 2026 23:13
@mafredri
mafredri force-pushed the perf/site-monaco-chunk branch from 35d4a61 to 13c9108 Compare October 30, 2026 11:38
@mafredri
mafredri force-pushed the perf/site-monaco-chunk branch 2 times, most recently from 158e5ab to 0771b38 Compare November 4, 2026 11:02
@mafredri
mafredri force-pushed the perf/site-monaco-chunk branch from 0771b38 to efb20b8 Compare November 6, 2026 19:45
@linear-code

linear-code Bot commented Nov 13, 2026

Copy link
Copy Markdown

CODAGT-1081

Vite 8 codeSplitting.groups include each matched module's imports by
default, so the monaco group took React and Vite's preload helper, and
every page preloaded the monaco chunk and its stylesheet. Turn that off
for the lazily loaded monaco, xterm and emoji-mart groups. The radix-ui
group keeps the default, which avoids a radix-ui and Command chunk
import cycle.
Deleting the monaco, xterm and emoji-mart groups keeps monaco out of the
entry chunk as turning off includeDependenciesRecursively did, with the
same initial JS and no chunk import cycles, and without an option that
Rolldown pairs with strictExecutionOrder. These libraries no longer get
stable vendor chunk names.
A monaco group narrowed so it cannot match React still made index.html
load the 4,178,496-byte monaco chunk: the entry imports Vite's preload
helper from it.
An xterm group stays lazy: @XTerm imports neither React nor Vite's
preload helper, and adding one changes the up-front JS by 17 bytes. An
emoji-mart group takes React only when listed ahead of radix-ui; after
it, React stays in the radix-ui chunk.
@mafredri
mafredri force-pushed the perf/site-monaco-chunk branch from efb20b8 to eff8991 Compare November 18, 2026 14:53

This branch has not been deployed

No deployments
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