Skip to content

chat: a large paste no longer freezes the box for twenty seconds - #1401

Closed
AbirAbbas wants to merge 2 commits into
devfrom
fix/paste-words-linear
Closed

AbirAbbas wants to merge 2 commits into
devfrom
fix/paste-words-linear

Conversation

@AbirAbbas

Copy link
Copy Markdown
Collaborator

What

Pasting a large document into the box froze the surface. pastedWords asked windowsBackslashWord about every word by converting the whole remaining paste to a string and lowercasing it. A 4,000-line paste (a stack trace, a log, about 180KB and 16,000 words) made about 16,000 copies of up to 180KB each: quadratic, about twenty seconds of CPU on the surface's own goroutine. TestALargePasteIsOneEditAndNoLayout measured it as 21s, 6% of the whole tui3 suite. Its CPU profile was 47% slicerunetostring, 32% encoderune, 17% strings.ToLower, all under app.paste.

The question now reads at most the sixteen runes it can recognise (X:\ needs three, \\wsl.localhost\ sixteen). The rest of the paste path was audited for the same shape: readings are bounded at four, a failed reading stops at its first failed stat, and every other scan is one pass.

Proof

  • The old splitter's exact output is pinned as literals, recorded from the old code before the change: plain lines, drive paths, both WSL UNC hosts, single and double quotes with spaces, backslash escapes, mixed lines, and the full 4,000-line trace.
  • A law in PERF.md holds the path linear by bytes allocated: a 4,000-line paste may allocate at most 10x the bytes of a 1,000-line one. It counts bytes on purpose: the regression was one allocation per word, so an allocation count grows fourfold for the quadratic parser too, and a count-based version of this law passed against it. Mutation-tested: the fixed parser measures 5.1x, the exact old code 15.3x (red), and a worse variant 15.5x (red).
  • TestALargePasteIsOneEditAndNoLayout keeps every assertion and falls from 21s to 0.01s.
  • make pr-ready green (touched ./internal/tui3, the whole package serial with -count=1, 317s against 337s before).

Part of the test-speed wave with #1394, #1397 and #1398.

🤖 Generated with Claude Code

AbirAbbas and others added 2 commits September 23, 2026 10:09
pastedWords asked windowsBackslashWord about every word by converting the
whole remaining paste to a string and lowercasing it, so a 4,000-line paste
(a stack trace, a log) made about 16,000 copies of up to 180KB: quadratic,
twenty seconds of CPU on the surface's own goroutine. The question now reads
at most the sixteen runes it can recognise.

The old splitter's exact output is pinned for drive paths, both WSL UNC
hosts, quotes, escapes, mixed lines and the 4,000-line trace. A law in
PERF.md holds the paste path linear by BYTES allocated (a count of
allocations grows fourfold for the quadratic parser too, one copy per word,
and a count-based law passed against it). TestALargePasteIsOneEditAndNoLayout
falls from 21s to 0.01s, which was 6% of the whole tui3 suite.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@AbirAbbas

Copy link
Copy Markdown
Collaborator Author

Consolidated into #1419, which carries this change unchanged as its own commit alongside the rest of the test-speed wave.

@AbirAbbas AbirAbbas closed this Sep 23, 2026
@santoshkumarradha santoshkumarradha added bug Something the code does that it should not area:chat The v3 surface a person sits in front of (internal/tui3) labels Oct 3, 2026
@santoshkumarradha santoshkumarradha added this to the Chat & connections milestone Oct 3, 2026
santoshkumarradha pushed a commit that referenced this pull request Oct 24, 2026
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:chat The v3 surface a person sits in front of (internal/tui3) bug Something the code does that it should not

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants