Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a maximum file size for highlighting with an editor setting #4729

Closed
wants to merge 2 commits into from

Conversation

xEgoist
Copy link

@xEgoist xEgoist commented Nov 13, 2022

Problem

syntax highlighting can take so much resources to fire up especially with large files. Trying to open a very large file (100 mb file for example) will takes very long time for helix and will be very slow to navigate through.

This PR adds a language specific settings for the users to specify their desired maximum file size in bytes.

for example,

[[language]]
name = "c"
hl-max-size = 1000000

will stop the highlighting for any C files larger than 1mb.

Another option is making this a global settings, but I feel like making it a language specific provides more flexibility.

This should help users to specify the max size for the documents since
highlighting takes too much resources when file size increases.
This setting is language specific. Thus, can be configured in
languages.toml
@archseer
Copy link
Member

This should be global (under editor config) since all languages will degrade in parsing performance as size increases. And hl-max-size is not very descriptive.

@pascalkuthe
Copy link
Member

pascalkuthe commented Nov 13, 2022

I also think this should be a global option and we should also consider setting a default for this. While I really want helix to perform well for large files too, I think there is a ceiling where its just not realistic anymore. That default should probably be MUCH higher then 1MB tough. With #4716 and another PR I am working on locally right now I can still edit the largest file in the linux kernel (24mb) with treesitter enabled with only a small amount of lag and have no noticeable lag during navigation. A good default value might be 150mb to 200mb. A nice QOL feature would be displaying a warning to the user when such a large file is opened like "This file exceed the highlight-limit, treesitter related features like syntax highlighting were automatically disabled." (other editors like intellij do something similar I think)

@kirawi
Copy link
Member

kirawi commented Nov 13, 2022

I think memory usage is a concern though.

@archseer
Copy link
Member

150~200MB is a reasonable default, that's what I was thinking of using.

@kirawi kirawi added A-helix-term Area: Helix term improvements S-waiting-on-review Status: Awaiting review from a maintainer. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from a maintainer. labels Nov 14, 2022
@@ -381,6 +383,7 @@ impl Document {
path: &Path,
encoding: Option<&'static encoding::Encoding>,
config_loader: Option<Arc<syntax::Loader>>,
file_size_limit: usize,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: unsure if this should be a parameter by its own or part of config_loader.

@@ -1098,8 +1101,12 @@ impl Editor {
let id = if let Some(id) = id {
id
} else {
let mut doc = Document::open(&path, None, Some(self.syn_loader.clone()))?;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: it's possible to open the file and get the metadata from it and pass None to the function, stopping language config all together. I personally think it's not a good idea to do so.

@@ -57,6 +57,7 @@ on unix operating systems.
| `rulers` | List of column positions at which to display the rulers. Can be overridden by language specific `rulers` in `languages.toml` file. | `[]` |
| `bufferline` | Renders a line at the top of the editor displaying open buffers. Can be `always`, `never` or `multiple` (only shown if more than one buffer is in use) | `never` |
| `color-modes` | Whether to color the mode indicator with different colors depending on the mode itself | `false` |
| `syntax-max-file-size` | Specify the maximum file size in bytes to enable syntax highlighting | `150000000` |
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Better setting name?

This sets a default maximum size of 150mb to trigger syntax highlighting
while allowing the user to specify an editor setting
  `syntax-max-file-size` to change the value of the maximum size
it will also notify the user once a file is opened if the limit is
exceeded.
@xEgoist xEgoist changed the title added hl-max-size to specify maximum file size for highlighting Add a maximum file size for highlighting with an editor setting Nov 15, 2022
@kirawi kirawi added S-waiting-on-review Status: Awaiting review from a maintainer. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 16, 2022
@xEgoist xEgoist closed this Jul 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements S-waiting-on-review Status: Awaiting review from a maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants