airblade / vim-gitgutter

A Vim plugin which shows git diff markers in the sign column and stages/previews/undoes hunks and partial hunks.
MIT License
8.37k stars 297 forks source link

Nvim hangs on opening a 3MB json file #845

Closed TisnKu closed 2 years ago

TisnKu commented 2 years ago

What is the latest commit SHA in your installed vim-gitgutter? f19b6203191d69de955d91467a5707959572119b

What vim/nvim version are you on? v0.7.2

When opening the 3MB json file attached below, my nvim hangs indefinitely. I have to kill the whole terminal window. If I remove the plugin, it is normal again.

pairs.json.zip

airblade commented 2 years ago

Hmm, it's instantaneous for me on nvim v0.6.0. I'll upgrade nvim and try again.

airblade commented 2 years ago

In the meantime, perhaps you could turn on logging (let g:gitgutter_log=1), open the json file, and post the gitgutter.log file (which will be in the directory where gitgutter is installed) here.

And/or you could profile gitgutter.

airblade commented 2 years ago

Just tried with nvm v0.7.2 and it's still instantaneous.

airblade commented 2 years ago

When you open the json file and nvim hangs, does the file have any changes? (I assume it's in a git repo.)

TisnKu commented 2 years ago

The file was an empty file and the whole content was then added and not yet staged. I'll try to the log later.

TisnKu commented 2 years ago

Below is the log. gitgutter.log

airblade commented 2 years ago

Thanks for the log. I also profiled the process.

The profile shows that running the diff and processing the diff's output are fast. At this point we have a list of 400,001 elements: one per added line.

Each one of those elements requires a sign. The code tells nvim/vim to add the signs with the built-in function sign_placelist(list). And this built-in function is taking 99% of the time.

So the time is spent inside nvim/vim, not the plugin.

In this case I suggest configuring the plugin to stop when the number of signs exceeds a threshold. For example:

let g:gitgutter_max_signs = 500

See :help g:gitgutter_max_signs.

TisnKu commented 2 years ago

I see, thanks.