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

vscode cpu100% #507

Closed
yaolunmao opened this issue Sep 18, 2021 · 19 comments
Closed

vscode cpu100% #507

yaolunmao opened this issue Sep 18, 2021 · 19 comments

Comments

@yaolunmao
Copy link

安装了这两个包

@vicons/fluent": "^0.11.0", 
"naive-ui": "^2.18.2"

可能和volar插件有冲突,导致cpu占用过高

@johnsoncodehk
Copy link
Member

I tried vicons before but I can't reproduce. Please provide repro case, and your VSCode info by Help: About command.

@umbrella22
Copy link

umbrella22 commented Sep 18, 2021

@johnsoncodehk

版本: 1.60.1 (user setup)
提交: 83bd43bc519d15e50c4272c6cf5c1479df196a4d
日期: 2021-09-10T17:07:10.714Z
Electron: 13.1.8
Chrome: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Windows_NT x64 10.0.22000
Volar-plugin-version: 0.27.21

This is my vscode information. In the current version, not only the CPU is 100%, but also the memory will surge to 1gb-2gb, which makes me very distressed. Is there any way to get useful logs for you? Incidentally, I didn't close vetur because I needed its TS support

@johnsoncodehk
Copy link
Member

Already has issue #399, but I hard to getting a repro case.

Please follow steps to make a repro case:

  1. Disable all other extensions to exclude other performance issue.
  2. Gradually move your project settings / content to https://github.com/johnsoncodehk/volar-starter, until reproduce the problem. And remove unrelated settings / content to make a minimum reproduce.
  3. Please provide:
    • The minimum reproduce.
    • VSCode info by Help: About command.
    • What operates required to reproduce the problem.

I don't want to use issue template to force user provide all informations, but check the proformance issue that missing repro case / informations is very time consuming. I will close kind of this issues until repro case provided.

@umbrella22
Copy link

Thank you for your reminder

@yaolunmao
Copy link
Author

hello!I have uninstalled all extensions and only kept them:volar, but the problem still exists.
this is my vscode info:

Version: 1.60.1 (user setup)
Commit: 83bd43bc519d15e50c4272c6cf5c1479df196a4d
Date: 2021-09-10T17:07:10.714Z
Electron: 13.1.8
Chrome: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Windows_NT x64 10.0.22000

If you want to reproduce the problem,you can

git clone https://github.com/yaolunmao/volar-test.git
cd volar-test
npm i

then open this folder with vs code
then Double click App.vue in vscode
then

ctrl+shift+esc

see the taskmanager

@johnsoncodehk
Copy link
Member

johnsoncodehk commented Sep 19, 2021

The problem comes from two aspects:

  1. TS initialization time of vicons & naive-uiis too long. This problem can be reproduced in plain ts. Due to volar's overhead, the initialization time of using vicons & naive-ui in volar is longer than plain ts. The time in my macbook is about 55 seconds, and the time after optimization is 43 seconds.
  2. There are many .d.ts files in vicons & naive-ui, and file watcher watch all these files, which leads to the permanent system cpu using too high. Resolved by cancel to watch files that are not in the tsconfig include.

@u007
Copy link

u007 commented Sep 19, 2021

im having constantly cpu usage also on my linux machine on "vite": "^2.4.4", + "ant-design-vue": "^2.2.8",

@johnsoncodehk
Copy link
Member

Please try 0.27.23.

@plainheart
Copy link

Good job! I really appreciate it. The tired CPU with overwork could take a rest now.

@u007
Copy link

u007 commented Sep 21, 2021

ok it does drop to between 1 to 6% . thank you 🙏

@yaolunmao
Copy link
Author

Nice!The CPU is now between 1% and 5%,But my version was originally 0.27.23. I don't know why it works now. Hahaha

@johnsoncodehk
Copy link
Member

Glory belongs to reproduction provider @yaolunmao. :)

This issue has been raised a long time ago, but most people just complained or gave the lowest rating and didn't want to help solve it. If there is a repro case, I can solve it quickly usually.

@kikyous
Copy link

kikyous commented Sep 23, 2021

@johnsoncodehk
image
volar seems scan my project file for ever, this cause a cpu usage about 10%, why not use os fs event?

@johnsoncodehk
Copy link
Member

@kikyous I don't know the difference between these, currently I just use ts.sys.watchFile: https://github.com/johnsoncodehk/volar/search?q=%22ts.sys.watchFile%22

Can you provide some references, or a PR?

@kikyous
Copy link

kikyous commented Sep 23, 2021

I think use a lib like chokidar is a good choice:
https://github.com/paulmillr/chokidar

@kikyous
Copy link

kikyous commented Sep 23, 2021

tool like Chokidar use filesystem event to listen file change, insted of polling file system.

Chokidar does still rely on the Node.js core fs module, but when using fs.watch and fs.watchFile for watching, it normalizes the events it receives, often checking for truth by getting file stats and/or dir contents.

On MacOS, chokidar by default uses a native extension exposing the Darwin FSEvents API. This provides very efficient recursive watching compared with implementations like kqueue available on most *nix platforms. Chokidar still does have to do some work to normalize the events received that way as well.

On most other platforms, the fs.watch-based implementation is the default, which avoids polling and keeps CPU usage down. Be advised that chokidar will initiate watchers recursively for everything within scope of the paths that have been specified, so be judicious about not wasting system resources by watching much more than needed.

@johnsoncodehk
Copy link
Member

I think use a lib like chokidar is a good choice:
https://github.com/paulmillr/chokidar

Volar used chokidar at the beginning, but I forgot what caused me to deprecate it and use ts.sys.watchFile instead.

I can try it again, please open a new issue to track.

@kikyous
Copy link

kikyous commented Sep 23, 2021

It seems that I need configure vscode ts extension to use fs event:

"typescript.tsserver.watchOptions": {
    "watchDirectory": "useFsEvents",
    "watchFile": "useFsEvents",
    "useFsEvents": true,
    "usePolling": false
  }

or in tsconfig.json:
https://www.typescriptlang.org/docs/handbook/configuring-watch.html

@kikyous
Copy link

kikyous commented Sep 23, 2021

image
Now cpu usage is very low when idle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants