Skip to content

Warn before opening a file that looks like binary content as text - #754

Open
KAMI911 wants to merge 1 commit into
linuxmint:masterfrom
KAMI911:perf/warn-before-opening-binary-file
Open

Warn before opening a file that looks like binary content as text#754
KAMI911 wants to merge 1 commit into
linuxmint:masterfrom
KAMI911:perf/warn-before-opening-binary-file

Conversation

@KAMI911

@KAMI911 KAMI911 commented Aug 22, 2026

Copy link
Copy Markdown

Opening a binary file (an image, an executable, an archive, etc.) as text used to be extremely slow and got worse than linearly with file size: measurements showed a 1 MB file with binary content taking about 21 seconds to load and settle versus about 2.5 seconds for a normal 1 MB text file, and a 5 MB binary file did not finish loading even after 45 seconds. The cause is that content which cannot be cleanly decoded as text makes the file loader try each candidate character encoding in turn before falling back to a lossy conversion, and the resulting buffer of mostly unreadable characters is also expensive for the text view to lay out. This adds a quick check before loading starts: the first 8 KB of the file are read and scanned for a NUL byte, the standard heuristic also used by tools like git and diff to tell binary content from text. If a NUL byte is found, a dialog warns that the file does not look like a text file and opening it as text can be slow and will show unreadable content, and lets the user cancel or open it anyway. Loading proceeds exactly as before once confirmed, or for any file where no NUL byte is found in that initial chunk.

Opening a binary file (an image, an executable, an archive, etc.) as text used to be extremely slow and got worse than linearly with file size: measurements showed a 1 MB file with binary content taking about 21 seconds to load and settle versus about 2.5 seconds for a normal 1 MB text file, and a 5 MB binary file did not finish loading even after 45 seconds. The cause is that content which cannot be cleanly decoded as text makes the file loader try each candidate character encoding in turn before falling back to a lossy conversion, and the resulting buffer of mostly unreadable characters is also expensive for the text view to lay out. This adds a quick check before loading starts: the first 8 KB of the file are read and scanned for a NUL byte, the standard heuristic also used by tools like git and diff to tell binary content from text. If a NUL byte is found, a dialog warns that the file does not look like a text file and opening it as text can be slow and will show unreadable content, and lets the user cancel or open it anyway. Loading proceeds exactly as before once confirmed, or for any file where no NUL byte is found in that initial chunk.
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.

1 participant