Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

doom: disable slow features on large files #416

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

edwintorok
Copy link
Contributor

I regularly have to open files that are gigabytes in size (logfiles), or source code that contains hundreds of thousands of lines, in which case Neovim can hang for a long time on opening the file, and every action inside the file is very very slow (moving lines takes several seconds).

Some of the features which become very slow on large files include:

  • gitsigns
  • illuminate
  • the various treesitter plugins (and treesitter itself). I think this is because it needs to parse the file from the very beginning in order to highlight correctly, and that can take a long time. The fallback (default) highlighting in Neovim that uses regular expressions may be slower and imprecise in general, but at least it works with more reasonable speed on large files.
  • various other Vim features that the existing LargeFile plugin already disables

Since Doom-nvim is focused on performance I think it'd be appropriate to have a feature to deal with large files better.
It won't be pretty, but at least the file will open and you can edit it.

If I have time I can take a look at more gradual disabling of features (e.g. maybe treesitter highlighting itself is not too bad, it is just all the tree-sitter plugins that are very slow on large files), but meanwhile this might be useful for someone already.

I also have some scripts that can measure performance using hyperfine and some simple scenarios (e.g. fabricate a "large" file with thousands of lines and measure how long it takes to use a motion to go to the end and insert some characters). These scenarios are more than just the usual "vim startup time", which although important may miss the point in some cases: I think what matters is "time to first action" (similarly to how browser latency is sometimes measured as 'time to first byte'): if my editor is frozen for minutes and won't respond to anything I type when I open a file, then the fact that the editor "started up" in 10ms or 100ms matters little, what should be measured is how soon before the editor is able to receive user input. (And then all else being equal, a faster startup "display" time is of course desirable).

The scripts aren't quite finished yet, so they are not included in this PR. You can see their current state at https://github.com/edwintorok/doom-nvim/blob/main/tools/profileit.sh and https://github.com/edwintorok/doom-nvim/blob/main/tools/compare_perf.sh.
It is a bit tricky to automate bootstrapping of neovim from 2 different commits to compare performance in a reproducible way, and I don't currently have a way to automatically check whether bootstrapping of doom succeeded or not, if it hasn't then it'll print various warnings/errors and not initialize completely which will cause any performance comparisons to be invalid.

What do you think?

Checking lua/doom/modules/features/lsp/init.lua   1 warning

    lua/doom/modules/features/lsp/init.lua:214:9: unused variable source_map

Checking lua/doom/modules/langs/cc/init.lua       1 warning

    lua/doom/modules/langs/cc/init.lua:1:7: unused variable utils

Signed-off-by: Edwin Török <edwin@etorok.net>
Use LargeFile.vim to disable syntax highlighting on large files.
Gitsigns and treesitter cna also be very slow on large files
(e.g. gigabytes of logfiles), so disable these as well.

By default a file is considered "large" if it either exceeds 10000
lines, or 1MiB. The linecount is not known when first opening the
buffer, hence the need for a file size limit too.

Signed-off-by: Edwin Török <edwin@etorok.net>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant