Warn before opening a file that looks like binary content as text - #754
Open
KAMI911 wants to merge 1 commit into
Open
Warn before opening a file that looks like binary content as text#754KAMI911 wants to merge 1 commit into
KAMI911 wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.