neoclide / coc.nvim

Nodejs extension host for vim & neovim, load extensions like VSCode and host language servers.
Other
24.43k stars 954 forks source link

vim blocks for a few seconds while saving a file #3824

Closed jyd519 closed 2 years ago

jyd519 commented 2 years ago

Result from CocInfo

Describe the bug

In my project directory, open any file, then execute :w, the Vim will hangs about 5 seconds.

Reproduce the bug

I can reproduce the bug in other directories, but I'm sure the bug is related with the commit:

e820875 fix(extensions): use glob to check workspaceContainsfix(extensions): use glob to check workspaceContains

The root of the problem is related with glob function.

chemzqm commented 2 years ago

It should not block your vim since it's async executed on nodejs side, you should profile your vim first https://github.com/neoclide/coc.nvim/wiki/F.A.Q#how-could-i-profile-vim

fannheyward commented 2 years ago

The glob is used to check workspaceContains to activate extensions, this won't do anything on saving.

yaegassy commented 2 years ago

@jyd519 Is this occurring when using coc.nvim in a very, very large repository? For example, in such a directory, if the root of the workspace is resolved as project_root?

project_root
├── .git
├── sub_directory
├── ...snip (many, many directory)
└── sub_directory
jyd519 commented 2 years ago

There are about 5GB files in my workspace: du -d 1 -h .

Output:

656K    ./tools
319M    ./app
579M    ./test
 28K    ./config
740M    ./node_modules
171M    ./server
1.0G    ./manager
 24K    ./cert
 33M    ./doc
126M    ./build
156M    ./.git
 65M    ./data
1.9G    ./client
116K    ./share
5.0G    .
yaegassy commented 2 years ago

@jyd519 I think this is happening when extensions that use workspaceContains for activationEvents are installed...

What extensions do you use?

jyd519 commented 2 years ago

:CocList extensions

Output:

* coc-yank 1.2.1 ~/.config/coc/extensions/node_modules/coc-yank
* coc-ultisnips 1.2.3 ~/.config/coc/extensions/node_modules/coc-ultisnips
* coc-tabnine 1.3.7 ~/.config/coc/extensions/node_modules/coc-tabnine
* coc-prettier 9.3.0 ~/.config/coc/extensions/node_modules/coc-prettier
* coc-marketplace 1.9.0 ~/.config/coc/extensions/node_modules/coc-marketplace
* coc-jest 1.1.4 ~/.config/coc/extensions/node_modules/coc-jest
* coc-eslint 1.5.8 ~/.config/coc/extensions/node_modules/coc-eslint
* coc-emoji 1.3.0 ~/.config/coc/extensions/node_modules/coc-emoji
* coc-browser 1.5.0 ~/.config/coc/extensions/node_modules/coc-browser
+ coc-yaml 1.7.5 ~/.config/coc/extensions/node_modules/coc-yaml
+ coc-vimlsp 0.12.8 ~/.config/coc/extensions/node_modules/coc-vimlsp
+ coc-tsserver 1.10.4 ~/.config/coc/extensions/node_modules/coc-tsserver
+ coc-toml 1.2.5 ~/.config/coc/extensions/node_modules/coc-toml
+ coc-sumneko-lua 0.0.28 ~/.config/coc/extensions/node_modules/coc-sumneko-lua
+ coc-sh 0.6.1 ~/.config/coc/extensions/node_modules/coc-sh
+ coc-rust-analyzer 0.62.0 ~/.config/coc/extensions/node_modules/coc-rust-analyzer
+ coc-markmap 0.6.1 ~/.config/coc/extensions/node_modules/coc-markmap
+ coc-json 1.4.2 ~/.config/coc/extensions/node_modules/coc-json
+ coc-go 1.3.0 ~/.config/coc/extensions/node_modules/coc-go
+ coc-cmake 0.2.1 ~/.config/coc/extensions/node_modules/coc-cmake
+ coc-clangd 0.21.4 ~/.config/coc/extensions/node_modules/coc-clangd
+ coc-angular 13.3.6 ~/.config/coc/extensions/node_modules/coc-angular
yaegassy commented 2 years ago

@jyd519 Try temporarily uninstalling coc-clangd, coc-rust-analyzer and coc-angular.

:CocUnistall coc-clangd
:CocUnistall coc-rust-analyzer
:CocUnistall coc-angular

If you then start vim/neovim and try :w, does it change the behavior?

jyd519 commented 2 years ago

Even simple :CocInfo, CocDisable takes the vim unresponsively.

I tried to revert commit 05dc868d, the problem gone.

git log

* 05dc868d - (HEAD -> master) Revert "fix(extensions): use glob to check workspaceContains" (6 minutes ago) <jyd519>
* 4524ef1f - (origin/master, origin/HEAD) fix(util): fix error on notification (22 hours ago) <Qiming Zhao>
...
jyd519 commented 2 years ago

@jyd519 Try temporarily uninstalling coc-clangd, coc-rust-analyzer and coc-angular.

:CocUnistall coc-clangd
:CocUnistall coc-rust-analyzer
:CocUnistall coc-angular

If you then start vim/neovim and try :w, does it change the behavior?

Thank you. It works. I'm gonna find out which one caused it.

yaegassy commented 2 years ago

@jyd519 I just wanted to isolate the problem. Thanks for the confirmation.

@chemzqm It appears that the blocking is occurring from a change in the feature of workspaceContains...

chemzqm commented 2 years ago

How to reproduce?

chemzqm commented 2 years ago

I've tried use glob to search files in my home folder, it doesn't block the node process.

yaegassy commented 2 years ago

@chemzqm @fannheyward The HOME directory is excluded from "WorkspaceFolders" resolution, so this problem may not occur. :echo WorkspaceFolders -> []

I think it can be reproduced by starting Vim8/Neovim one directory down from the HOME directory.

chemzqm commented 2 years ago

I mean execute the glob related code

const glob = require('glob')

let i = 0
setInterval(() => {
  console.log(i++)
}, 1000)

let gl = glob('**/*', {
  nosort: true,
  dot: true,
  cwd: process.cwd(),
  nodir: true,
  absolute: false
}, err => {
  console.log(err)
})

gl.on('end', () => {
  console.log('end')
})

I think it can be reproduced by starting Vim8/Neovim one directory down from the HOME directory.

Can't reproduce.

yaegassy commented 2 years ago

I will let you know when I come up with an easy way to reproduce it. I reproduced it in my environment.

For example, I tried it on the golang package directory, where there would be many directories and files. Create markdown as a sample.

https://user-images.githubusercontent.com/188642/168812559-5d62331d-6788-4a65-b71f-c6976c4737b7.mp4

jyd519 commented 2 years ago

I located the problem is related to the coc-rust-analyzer plugin.

https://github.com/fannheyward/coc-rust-analyzer/blob/master/package.json#L20

  "activationEvents": [
    "onLanguage:rust",
    "workspaceContains:**/Cargo.toml"
  ],

glob("**/Cargo.toml", ...) in a directory with many sub directories and files , such as node_modules is very slow.

yaegassy commented 2 years ago

@jyd519 This problem may have been solved with this commit. Try it in your environment. https://github.com/neoclide/coc.nvim/commit/1d2d28638b241bcc9cc91008580e2724ce767f7c

jyd519 commented 2 years ago

@yaegassy The commit solved the issue, I can't feel any delay. Thanks for your hard works!