Skip to content

fix(app): prevent large paste stalls - #41579

Open
vanthunder wants to merge 1 commit into
anomalyco:devfrom
vanthunder:paste-performance
Open

fix(app): prevent large paste stalls#41579
vanthunder wants to merge 1 commit into
anomalyco:devfrom
vanthunder:paste-performance

Conversation

@vanthunder

Copy link
Copy Markdown

Issue for this PR

Closes #38932

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Large multiline pastes in the V2 composer were routed through execCommand("insertText"), causing Chromium to create a DOM node per line and block the renderer.

This applies those pastes directly to the prompt model instead, preserving the text as normal editable prompt content. It also bounds related editor scans and reduces unnecessary draft persistence work.

This is an alternative approach to #38934, which converts large pastes into temporary file attachments.

How did you verify your code works?

  • Full pre-push typecheck: 30/30 tasks passed
  • session-ui: 96 tests passed
  • app: 722 unit tests and 58 browser tests passed
  • Composer performance suite: 40/40 passed
  • 100 KiB multiline paste: ~13.9 s → ~49 ms
  • 256 KiB paste: timeout → ~105 ms
  • 1 MiB paste: timeout → ~411 ms
  • Packaged Windows Electron build tested with a 12,000-line paste
  • No renderer unresponsive event, render-process-gone event, or crash observed

Screenshots / recordings

N/A — this is a performance/behavior fix without a visual UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

The V2 composer routed every paste carrying text/plain straight into
execCommand("insertText"), so its large-paste guard was unreachable and the
browser built one DOM node per line. Every following keystroke then had to
walk that document back into prompt parts. Large pastes now apply to the
prompt model directly, honouring the selection and the caret. Legacy got
this in 7e681b0; V2 never did.

Also bounds the cursor and suggestion scans, coalesces draft writes before
the IPC hop, and stops the desktop main process from reading every stored
draft back at startup.

100 KiB paste: 13.9 s -> 42 ms. 256 KiB and 1 MiB did not complete before.
@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Found a related PR:

#38934: fix(app): convert large paste to file attachment
#38934

This is closely related as the current PR mentions it explicitly: "This is an alternative approach to #38934, which converts large pastes into temporary file attachments." Both PRs address the same issue (#38932) but use different strategies to handle large multiline pastes in the V2 composer to prevent renderer stalls.

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.

Pasting a long text in prompt box make Desktop app hang

1 participant