vuejs / language-tools

⚡ High-performance Vue language tooling based-on Volar.js
https://marketplace.visualstudio.com/items?itemName=Vue.volar
MIT License
5.76k stars 388 forks source link

vscode cpu100% #507

Closed yaolunmao closed 2 years ago

yaolunmao commented 2 years ago

安装了这两个包

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

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

johnsoncodehk commented 2 years ago

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

umbrella22 commented 2 years ago

@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 commented 2 years ago

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 commented 2 years ago

Thank you for your reminder

yaolunmao commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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

johnsoncodehk commented 2 years ago

Please try 0.27.23.

plainheart commented 2 years ago

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

u007 commented 2 years ago

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

yaolunmao commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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

johnsoncodehk commented 2 years ago

@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 commented 2 years ago

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

kikyous commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

image Now cpu usage is very low when idle