Skip to content

Speed up large composer paste and first thread open - #5

Open
jjcm wants to merge 6 commits into
mainfrom
cursor/composer-paste-and-thread-open-perf-cf7d
Open

jjcm wants to merge 6 commits into
mainfrom
cursor/composer-paste-and-thread-open-perf-cf7d

Conversation

@jjcm

@jjcm jjcm commented Aug 18, 2026 •

Copy link
Copy Markdown
Owner

Combines the product keepers from #4 and #3 into one reviewable PR. A 1 MB paste into the composer now paints in ~0.5 s instead of ~2.5 s, and the first thread open of a session stays at ~242 ms instead of regressing to ~469 ms behind a lazy boundary.

Scenario Before After
1 MB composer paste, rich text on, until painted 2453 ms 530 ms
  isolated Markdown parse of that paste 2362 ms 11.9 ms
First thread open in a session (lazy pane vs static) 469 ms 242 ms (−48.5%)

1 MB paste, before/after (mp4):

1 MB paste before/after

First thread open, before/after (mp4) — production build, real timescale slowed 8×, counter freezes at each side's painted time (399 ms lazy vs 126 ms static on the recording machine; medians over 5 runs were 405 ms vs 146 ms):

First thread open before/after

Changes

  • Markdown parse linearization (prompt-editor-serialization.ts): parsing a large single-line paste was superlinear; it is now linear, taking the isolated parse from 2362 ms to 11.9 ms on a 1 MB minified-JS paste. This is the headline paste win.
  • Typeahead trigger window (find-active-trigger.ts): the @// trigger scan looks at the last 256 characters before the caret instead of rescanning the whole text on every keystroke.
  • Structural value compare (PromptBoxInternal.tsx): the controlled-value sync compares text and mention ranges structurally instead of JSON.stringifying the entire prompt twice per keystroke.
  • Draft flush serialization (usePromptDraftStorage.ts): the localStorage draft serializes on the existing 250 ms flush, not on every keystroke.
  • Deferred decoration rebuild (prompt-decoration-extension.ts): above 100k positions the decoration rebuild is deferred. Tradeoff: decorations can lag typing by up to ~200 ms on very large drafts.
  • Thread view stops subscribing to draft state (ThreadDetailView.tsx): it reads the draft only when a quote is added, so the whole thread view (timeline included) no longer re-renders on every composer keystroke.
  • Thread pane stays a static import (SplitThreadArea.tsx): Fix composer jank when a large minified-JS blob is pasted #1 proposed a React.lazy boundary here; measurement showed it makes the first thread open 469 ms instead of 242 ms (the Suspense retry mounts the pane at transition priority — prefetching the chunk recovers only ~7 ms). This PR keeps the static import and pins the measurement in a comment. Tradeoff: the thread view (~899 KB raw) ships in the workspace route chunk instead of a click-time round trip.

Notes

AGENT GENERATED: by Claude Fable 5

Open in Web Open in Cursor 

cursoragent and others added 4 commits August 18, 2026 20:38
Pasting a large single-line payload (a minified JS bundle is the case that
surfaced this) froze the composer for tens of seconds, and every keystroke
afterwards stayed expensive. The work was spread across five synchronous
paths, all of which scaled with the size of the whole document:

- Markdown parsing rescanned the full text per delimiter candidate and per
  emitted run, which is quadratic on delimiter-dense input. Marker/mention
  lookups now use a sorted range index and monotonic sweeps.
- The typeahead trigger scan rebuilt all text before the caret on every doc
  and selection update; it now scans a bounded window.
- The controlled-value sync key JSON-stringified the whole prompt twice per
  keystroke; it now compares structurally, normally on pointer identity.
- Draft storage serialized the full draft on every write even though the
  write itself was already debounced; serialization moved to the persist
  boundary.
- Decoration rebuilds serialized the document and ran every rule over the
  full text per edit; above 100k positions they now map through the edit and
  rebuild on a throttled timer.
- ThreadDetailView subscribed the whole thread view to draft state, so the
  timeline re-rendered per keystroke; it now uses the non-subscribing
  accessor it already had available.

Co-authored-by: Jacob Miller <[email protected]>
ThreadDetailView remains a static import in SplitThreadArea: a React.lazy
boundary there made the first thread open of a session take 469 ms instead
of 242 ms (the Suspense retry mounts the pane at transition priority), and
prefetching the chunk recovered only ~7 ms. Document that measurement on the
import so it is not re-lazied without a new measured reason.

Also add the 1 MB paste before/after clip under perf-clips/ so it renders in
the pull request.

Co-authored-by: Jacob Miller <[email protected]>
Side-by-side recording of the first thread open on the production build:
lazy thread pane (as proposed in #1) versus the static import kept by this
branch. Real timescale slowed 8x; the counter freezes at each side's painted
time (399 ms lazy, 126 ms static on the recording machine).

Co-authored-by: Jacob Miller <[email protected]>
@jjcm
jjcm marked this pull request as ready for review August 18, 2026 21:09
jshph and others added 2 commits August 18, 2026 16:15
## User-facing problem

On iPhone, submitting a follow-up can feel like the button ignored the
first tap:

1. The user taps Submit.
2. The keyboard closes and the composer shrinks.
3. The message remains unsent.
4. The user has to tap Submit again.

This is especially confusing because it resembles network lag, even
though the first submission never actually committed.

## What this changes

The submit button now checks which DOM element the browser actually
considers focused instead of relying on TipTap's event-derived focus
flag.

During the brief iOS focus transition where those states can disagree,
bb keeps the editor and keyboard stable long enough for the first tap to
produce its click. After submission commits, the existing keyboard
dismissal and compact-composer behavior continue normally.

The change is intentionally narrow: genuine focus outside the editor
behaves as before, and desktop submission behavior is unchanged.

## Verification

- Added a regression test that models stale TipTap focus while the
contenteditable still owns native focus.
- All 98 PromptBoxInternal tests pass.
- Turbo app typecheck passes.
- Prettier and git diff checks pass.

> AGENT GENERATED: by GPT-5
…te-and-thread-open-perf-cf7d

# Conflicts:
#	apps/app/src/hooks/usePromptDraftStorage.test.tsx
#	apps/app/src/hooks/usePromptDraftStorage.ts
#	apps/app/src/views/thread-detail/ThreadDetailView.tsx

Co-authored-by: Jacob Miller <[email protected]>
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.

3 participants