Skip to content

Cut the editor stack out of Home's first load, and start the pad's editor chunks sooner #733

Open

Description

@HMarzban

Part of #571. Builds on #732.

Summary

After #732, _app is still 681 kB, and Home loads 952 kB of first-load JS. Most of it is editor code Home never uses: ProseMirror, Tiptap, Yjs, Virtuoso, the sheet frame and DiceBear. Four import chains and one module-load cost (C5) pull it in. This issue cuts them one step at a time. It also starts the pad's editor chunks sooner, so the pad does not get slower. It also owns the CI bundle budget (step 6).

Benchmark

Field Value
Metric Home JS over the wire, in bytes (exact). Route table first-load JS for /, /[...slugs] and _app, in kB. Pad guard: t2, ms from navigation start to the first sync step 2 frame received on the collab WebSocket.
Before Home JS: 965,119 B (0b302b222, 2026-11-11 11:13Z, #732 comment of 11:20Z). Route table: 952 / 925 / 681 kB (0b302b222 deploy log, build:ci, read 2026-11-11). Home Lighthouse is context only. The 11:13Z set: LCP 7.35 s (7.26–7.80), TBT 254 ms (251–272), FCP 1.33 s (1.22–1.56), TTFB 211 ms, n = 5. The 17:14Z rerun on the same commit: TBT 308 ms (287–330), FCP 1.15 s, TTFB 115 ms (#732 close comment). The maintainer takes a fresh n = 5 Home before on the day of step 3, after the #741 step 3B deploy, with TTFB recorded. Pad timeline: not measured yet: agent in the repo (local) and maintainer (production /demo) take it before step 3.
After not measured yet
Confounds #741 step 3B (GA off), #738, #734 step 1, #751, #736 and #747. Take each before and after pair with none of these deployed in between. Record the deploy hash of every run. Re-take the before if one lands.
Condition Home: production, Lighthouse 12.8.2, Chrome 157, default mobile (simulated 150 ms RTT, 1,638.4 Kbps, 4x CPU), the #732 laptop, n = 5, median (min–max). Pad: packages/document-swarm/src/pad-timeline.ts (method below), cold context, 1440 × 900. Lighthouse is never used on a pad.
How to run Route table: build:ci. Home bytes: the #732 byte method (each <script src> in Home's HTML, gzip, summed). Pad: bun packages/document-swarm/src/pad-timeline.ts --url <url> --runs 10.
Pass rule Each step: every route-table value smaller or equal; /[...slugs] must not rise. Step 3: Home wire bytes fall by at least 60 % of the / route-table drop. Pad gate: see step 3. Revert a step that fails its gate.
Guard Pad open time (step 3 gate) and the UX checks below. Step 5: a test error still carries contexts.trace.trace_id, which #751 and #752 count by.
Owner Agent in the repo: steps 1-6, route tables, the local timeline. Maintainer: production Lighthouse, the production timeline, the phone checks, and the budget limits.
Claim "Home's JavaScript over the wire fell from 965,119 B to X B (gzip) in v2.3.7, and pad first sync stayed within % of before (median, n = 10, production /demo, simulated slow link)."
Step Row Before After (pass) Condition n
each Route table /, /[...slugs], _app 952 / 925 / 681 kB (0b302b222) each smaller or equal; /[...slugs] must not rise build:ci exact
3 Home JS over the wire 965,119 B (0b302b222) falls by at least 60 % of the / route-table drop #732 byte method, gzip exact
3 Home LCP, TBT, FCP fresh n = 5 set on the day of step 3 (the 11:13Z and 17:14Z sets are context) LCP and TBT within the A/A gate (step 3); record the LCP element and its render delay Home condition 5
3 Scratch pad: t1 WebSocket open, t2 first sync not measured yet medians at most before + 50 ms; max not worse by more than 10 % Pad condition, local production build 10 cold
3 /demo: t2 first sync, t4 throttled fill not measured yet t2 median at most before + 5 % Pad condition, production, load only 10 cold
3 First DocumentPage chunk request starts before _app ends not measured yet record yes / no per run (the preload fallback targets 10 of 10) Resource Timing, same runs 10
5 Test error carries contexts.trace.trace_id yes yes local, dummy DSN 1
6 Routes guarded by a CI budget 0 3 build:ci; one deliberate red run exact

Pad timeline method

Commit it as packages/document-swarm/src/pad-timeline.ts.

  • Playwright Chromium. A new context per cold run: no HTTP cache, no service worker, no IndexedDB. Viewport 1440 × 900.
  • CDP Network.emulateNetworkConditions: latency 150, download 209,715 B/s, upload 86,400 B/s. Emulation.setCPUThrottlingRate: 4.
  • CDP throttling may not delay WebSocket frames. So the script checks it first. It times one known first-sync frame against its byte size. If the frame arrives faster than 209,715 B/s allows, CDP did not throttle it. Then route the collab socket through a TCP proxy like the Show "synced" only after the server confirms the edit #736 one, at the same latency and rate. Print which path ran.
  • Marks from navigation start:
    • t1: Network.webSocketCreated for the collab host.
    • t1b: the first received frame on it, the auth reply.
    • t2: the first received frame on the collab socket that decodes as a sync message (outer type 0, sync step 2). The provider sends its token first, then starts sync (@hocuspocus/provider 3.4.4), so the first frame is not a sync message.
    • t3: skeleton gone and editor ready.
    • t4 throttled fill: heading count stable for 2 s, under the CDP throttle. It is not the house pad fill time, which comes from fillcheck.ts. Never compare the two.
  • Also record the JS encodedDataLength before t1. From Resource Timing, record whether the first DocumentPage chunk request starts before the _app response ends.
  • Discard a run that never fills, and re-run it.
  • Output: median and range per mark.
  • Local runs use a scratch pad that the script creates on the local stack and deletes after. Production runs only load /demo. Nobody types into /demo.
  • Never compare pad timeline numbers with Home Lighthouse numbers. Lighthouse simulates its throttle; this script applies it.
  • Ruled B, 2026-11-16: the script lives in packages/document-swarm, which already has playwright 1.64.1.

Cause (read from code)

Cut Chain into Home Line
C1 _app loads BottomSheet, which loads 14 sheet bodies statically, with the editor stack apps/webapp/src/pages/_app.tsx:6, :220; components/BottomSheet.tsx:1-29
C2 useProfileSync (every route) → the @api barrel → fetchLinkMetadata.ts → the whole hyperlink extension, for normalizeHref api/users/fetchLinkMetadata.ts:1; api/index.ts:8
C3 Settings constants import a Tiptap helper components/settings/constants.ts:3
C4 CommandJump → historyShareUrl.ts → history/helpers.ts → Yjs and the transformer, for formatVersionDate components/pages/history/historyShareUrl.ts:7
C5 Avatar builds the DiceBear fallback at module load components/ui/Avatar.tsx:5-6, :32

The cuts depend on each other. C2 to C4 alone save about 6 kB, because the sheet bodies hold the same modules. With C1, they matter.

C1 alone makes a pad slower. Today the editor stack is inside _app (through BottomSheet, C1), and the DocumentPage chunks load after _app (corrected 2026-11-13). With C1 alone, the stack would download only after _app runs. So C1 ships with a warm-up of the pad chunks (step 3), and the step 3 gate measures it.

Steps

Each step is one commit. Each records its before and after. Agent in the repo builds every step. The maintainer pushes each with a (build): front tip.

  1. C3 and C4. Move formatVersionDate into its own small file. Replace the Tiptap isMacOS import with a local check.
  2. C2. Change hooks/useProfileSync.ts and hooks/useNotificationPreferences.ts to import from their own files by relative path (api/users/getUserById.ts and api/rpc/getNotificationPreferences.ts), not from the @api barrel. tsconfig.json has no @api/* alias. Also cut the chain HomePage.tsx -> ui/Avatar.tsx -> ui/dialogs/UserProfileDialog.tsx -> api/users/fetchLinkMetadata.ts (2026-11-13), or the hyperlink extension stays in /. Confirm with the route table that the hyperlink extension leaves _app. The hyperlink package exports only ., so normalizeHref has no subpath import.
  3. C1 and the warm-up, together.
    • Load BottomSheet with next/dynamic and ssr: false. On non-document routes, start the BottomSheet import after the load event. Schedule it with requestIdleCallback(cb, { timeout: 2000 }) where it exists, else setTimeout(cb, 1), as utils/ensureEmojiData.ts does. It still mounts closed before any open. Do not mount it on first open: a late history push hits the Safari back race of Chat icon in the phone TOC drawer does not open the chat on iPhone Safari #639.
    • Keep one sheet system, and keep it inside AppQueryClientRoot.
    • A chunk failure while offline must show an error path, because openSheet alone shows nothing.
    • In pages/[...slugs].tsx, start import() of DocumentPage at module scope, so its chunks download while _app runs.
    • Record Home wire bytes (the Load only the 71 brand icons the social links use, so Home stops shipping three whole icon packs #732 method) beside the route table.
    • A/A pair first. Two before sets run on one day. Each gate is "after median at most before median + max(stated bound, A/A median gap)". Quote "lower" only when the after median is below the before minimum.
    • Pad gate. Local production build (build:ci, then start:prod), one scratch pad, n = 10 cold runs per side. Pass: t1 and t2 medians at most before + 50 ms, and max not worse by more than 10 %. Production /demo, n = 10 per side, for the claim. Pass: t2 median at most before + 5 %.
    • Fallback, if the gate fails. Emit <link rel="preload" as="script"> for the DocumentPage chunk files, read from .next/react-loadable-manifest.json, in _document.tsx on pad routes only. Record the timeline for both variants.
  4. C5. Load the DiceBear fallback on idle, with the same requestIdleCallback and setTimeout fallback as step 3. Show a same-size skeleton rounded-full bone until it is ready.
  5. Sentry tracing code. Set bundleSizeOptimizations: { excludeDebugStatements: true, excludeTracing: true } at apps/webapp/next.config.js:431 (tracesSampleRate is 0). Record _app kB before and after. Verify: one local test error, with a dummy DSN on localhost:9, still carries contexts.trace.trace_id in its envelope. Record whether a client navigation changes trace_id, before and after step 5. After step 5, one trace is one page load. So step 5 ships last, after the Patch y-indexeddb so a closed offline copy cannot stop pad updates, and WebKit can compact it #751 and Make GlitchTip browser counts usable: one Safari IndexedDB event per page load, no service-worker register noise #752 7-day reads.
  6. CI bundle budget (from [Tracking] Make docs.plus pages load faster: web bundle and page speed #571). A Bun script after build:ci reads .next/build-manifest.json. For / and /[...slugs], it takes the union of pages[route] and pages['/_app']. For _app, it takes pages['/_app'] alone. It keeps .js files only, gzips each with Bun.gzipSync, and sums the bytes. Neither route list holds the _app chunk, and pages['/_app'] also lists a CSS file. Check once that each total is within 1 % of the build:ci route table before setting limits. The script exits 1 above budget. Budget = this issue's after plus 5 %. Prove it with a red run from a deliberate oversize import. The maintainer approves the limits.

Out of scope:

  • Hoisting the collab provider into the page. It needs a ruling and the step 3 numbers first.
  • Toolbar re-renders. Measure them with React Profiler first.
  • Dropping mobile-detect. Client and server must agree on "mobile".

UX checks (each step)

Devices: iOS 27 Safari on an iPhone, current Android Chrome, desktop Chrome 157 and desktop Safari 27. The maintainer runs the phone checks.

  • No new flash or blank frame on Home or the pad. Light and dark, 390 px and 1280 px.
  • Step 3, on iOS Safari and Android Chrome:
    • Sign-in opens on Home. On iOS Safari, it also opens right after load.
    • The TOC drawer hands off to filters.
    • A slash command keeps the keyboard up (scratch pad, never /demo).
    • The gallery and the Documents row menu open inside their parent.
    • Hardware Back closes one sheet at a time.
    • An offline chunk failure shows the error path.
    • On a scratch pad the agent creates on the local stack: go offline, reload, type / at 390 px. The slash-menu sheet opens. Delete the pad after.
  • Step 4: a signed-in Home with no photo shows the bone, then the face, with no shift.
  • Step 5: an error still reaches GlitchTip, with contexts.trace.trace_id.

Rollback

Each step is one commit. Revert it and push a (build): front tip.

Acceptance criteria

  • The Home before and the route tables are in a Measured comment before the first commit. The pad timeline before is in a Measured comment before step 3.
  • Each step's route table is in its comment.
  • The step 3 pad gate passes, locally and on production /demo.
  • Every UX check passes.
  • The step 6 budget job is red on a deliberate oversize import and green on main.
  • The production after Measured comment exists, with the same settings.
  • The v2.3.7 benchmark ledger: every quotable claim, with n, range, condition and source #796 Web speed row holds the after numbers and links the after Measured comment.

Activity

  1. added this to the v2.3.6 milestone on Nov 11, 2026
  2. added
    Performance
    on Nov 11, 2026
  3. modified the milestones: v2.3.6, v2.3.7 on Nov 13, 2026
  4. HMarzban commented on Nov 13, 2026

    @HMarzban
    CollaboratorAuthor

    Maintainer ruling, 2026-11-13: moved to v2.3.7. C1 needs the pad gate. The gate needs scripts/bench/pad-timeline.ts, which needs playwright-core, and that ruling is due 2026-11-19. No pad before exists yet.

    Confounds to record before the Home before: #701 (editor stack) and c9cd2c98a (extension-hyperlink autolink fix), which ships with the 2026-11-14 webapp roll. C2 must also cut the chain HomePage.tsx -> ui/Avatar.tsx -> ui/dialogs/UserProfileDialog.tsx -> api/users/fetchLinkMetadata.ts, or the hyperlink extension stays in /.

  5. HMarzban commented on Nov 13, 2026

    @HMarzban
    CollaboratorAuthor

    Step 6 note from the 2026-11-13 production before (#763 Measured): the pad budget misses the editor chunks.

    At 9f132692e, /demo HTML loads 8 scripts: polyfills, webpack, framework, main, _app, [...slugs] and the two manifests. It loads no editor chunk. DocumentPage is next/dynamic with ssr: false (apps/webapp/src/pages/[...slugs].tsx:32), so its chunks start only after _app and the page chunk run. The [...slugs] chunk is 5,635 B on the wire.

    Two changes follow:

    1. Step 6 budget. pages['/[...slugs]'] plus pages['/_app'] from .next/build-manifest.json does not hold the DocumentPage chunks. For the pad route, also add the DocumentPage entry from .next/react-loadable-manifest.json (the file the step 3 fallback already reads). Keep build-manifest.json and react-loadable-manifest.json in the CI artifact, so each budget run can be checked later.
    2. Cause section. "Today the editor chunks are HTML script tags that download in parallel with _app" does not match production. Today the editor stack is inside _app (through BottomSheet, C1), and the DocumentPage chunks load after _app. C1 alone still makes a pad slower: the stack would then download after _app runs. So the step 3 warm-up and gate stay as written.

    No action is needed on steps 1 to 5.

  6. HMarzban commented on Nov 16, 2026

    @HMarzban
    CollaboratorAuthor

    Maintainer ruling, 2026-11-16

    Answered by the maintainer in the 2026-11-16 working session; posted by the agent.

    • playwright-core: B, put pad-timeline.ts in packages/document-swarm, which already has playwright 1.64.1. This is not the thread's recommended option (A, a root devDependency); B is the deliberate choice.
  7. HMarzban commented on Nov 16, 2026

    @HMarzban
    CollaboratorAuthor

    Review, 2026-11-16 (maintainer approved).

  8. modified the milestones: v2.3.7, v2.4.0 on Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Performance

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions