Skip to content

Open long files without freezing the window - #153

Merged
dhh merged 2 commits into
masterfrom
open-large-files
Nov 12, 2026
Merged

dhh merged 2 commits into
masterfrom
open-large-files

Conversation

@dhh

@dhh dhh commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #137.

Opening a long file styled it twice: setPlainText, then applyDocumentTypography changing every block's format, which the highlighter followed with a second pass over the whole document. And Qt Quick drew every line into the first frame, because it only limits a TextEdit to its viewport for text set through TextEdit.text, never through its document.

  • loadDocumentText clears the document and inserts the text under the line height in one edit block, with undo off, so the file is styled once and there's one change notification.
  • attachDocument sets ItemObservesViewport on the editor, so only what is on screen is drawn.

On a 7.5 MB, 92k-line FASTA file like the one in the issue, offscreen:

Main-thread CPU Memory
Before ~5 s 1,390 MB
After ~1 s 790 MB

Most of the remaining memory is Qt itself: a bare QTextDocument holding that file and laid out at the editor's width takes about 730 MB. Going lower would mean not using TextEdit.

This is the load-path half of #133 by @AgentRBY (credited as co-author), brought onto the CMake build, with the clear moved inside the edit block and the stale comment on applyDocumentTypography fixed. #133's popup and QML-compilation changes are left to that PR.

🤖 Generated with Claude Code

Opening a long file styled it twice, once in setPlainText and again in a
typography pass over every block, and drew every line of it into the
first frame, since Qt Quick only limits drawing to the viewport for text
set through TextEdit.text. A 7 MB file took about 5 seconds of the main
thread and 1.4 GB.

The text is now inserted under the line height in one edit block, and
the editor draws only what is on screen. The same file opens in about a
second and 790 MB, most of which is Qt's layout of every line.

Fixes #137

Co-Authored-By: AgentRBY <mrget112@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The follow-up appears safe to merge.

Summary

This PR reduces repeated work when opening long files and limits drawing to the visible text.

  • Long files now load with one formatting pass and draw only visible lines.

No new issues found in the follow-up changes.

Reviews (3) · Last reviewed commit: "Check that opening a file changes the do..." · Reviewed by Greptile

Comment thread tests/omawrite_tests.cpp Resolved
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dhh
dhh merged commit 38921bb into master Nov 12, 2026
2 checks passed
@dhh
dhh deleted the open-large-files branch November 12, 2026 15:07
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.

Opening a large file (~7 MB, 92k lines) consumes multiple GB of memory and freezes the window for minutes

1 participant