vetur: High CPU Usage

  • I have searched through existing issues
  • I have read through docs
  • I have read FAQ

Info

  • Platform: macOS 10.14.1 (18B45d)
  • Vetur version: 0.14.5 from Marketplace
  • VS Code version: 1.31.0-insider
{
  ...
  "files.watcherExclude": {
    "**/node_modules": true,
    "**/platforms": true,
    "**/plugins": true
  },
  ...
  "vetur.format.defaultFormatter.html": "none",
  "vetur.format.defaultFormatter.js": "vscode-typescript",
  "vetur.format.defaultFormatterOptions": {
    "prettier": {
      "singleQuote": true,
      "trailingComma": "all"
    }
  },
  "vetur.format.scriptInitialIndent": true,
  "vetur.format.styleInitialIndent": true
  ...
}

Problem

image

Reproducible Case

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 10
  • Comments: 68 (21 by maintainers)

Commits related to this issue

Most upvoted comments

The Vetur extension is making VS Code nearly unusable for me.

A did some debugging and it looks like getSingleTypeDocument method is triggered for every vue file in our project for every single change / hover. The same files seems to be triggered several times (up to 6 times). Since we have around 400 files in our project, this causes a single change / hover to call this method 6*400 times = 2400 times

We are also facing the same issues with high cpu usage and poor performance in Vetur. It is actually so slow that we cannot use the extension.

It is a pretty large project with a combination of ts files as well as vue files. The big performance problems started when upgrading to 0.18 of vetur

Did some profile of the extension and it looks like the extension is spending a lot of time in “string.replace”.

image

According to the picture above, 16 seconds is spend in string.replace.

The above profile was triggered by writing and deleting a character in a vue file several times.

BTW, I’m running it on a Mac. I really hope this can get some attention soon. I love using VS Code, but it’s completely unusable as soon as I install Vetur and open a .vue file.

Code completion without our optimization: veturstandard

Code completion with our optimizations: veturoptimized

Since I am a total n00b when it comes to vscode, extensions and language server, my changes are probably breaking lots of things.

https://github.com/petternordholm/vetur/commit/4a55c28346b94ca4cdc72a505783fcb1b8bef540

What I dont really understand is why the language server is initialized with all .vue files in the project. With my change, only the currently edited file will be processed. Typescript itself will pull in all imports from the file and verify those as well.

I have same issue. Intelisense works slow in .vue file, and works fine in .ts.

  • VSCode 1.31.1, Win7 x64
  • Vetur 0.15.1
  • TypeScript 3.3.3

The project is not very lagre (~ 450 files).

tsconfig.json has:

{
    "compilerOptions": {
        "baseUrl": ".",
        "paths": {
            "@/*": ["src/*"]
        },
    },
    "include": [
        "src/**/*.ts",
        "src/**/*.tsx",
        "src/**/*.vue",
        "tests/**/*.ts",
        "tests/**/*.tsx"
    ],
}

But if I remove baseUrl everything works fine.

same issues, high cpu, can’t lint js/ts in .vue file, it work just disable vetur i can’t find a solution to the problem so i have replaced it with another plugin vscode-vue-snippets at least it doesn’t have the same problem

@octref Kudos for great work with the extension!!. Please find attached the profiling from 0.19.2

An easy way to improve performance is to use the following replace function instead, https://jsperf.com/optimized-replace/1 (in getSingleLanguageDocument & getSingleTypeDocument). According to jspref, it performs a lot faster than plain string replace. It should work with both windows and unix line endings.

We are currently using a locally patched version of vetur and the optimized replace makes the extension usable for us again.

Profiling with standard string.replace CPU-vetur-0.19.2.cpuprofile.gz

And profiling with optimized replace: CPU-vetur-0.19.2-optimized-replace.cpuprofile.gz

I don’t think it is fixed. I just saw a Code process using 368% CPU using the latest versions of Code and Vetur!

I don’t believe this is only caused by saving files. I can reproduce the issue simply by installing Vetur and opening a single .vue file.

@lisonge I rewritten the Vue TypeScript Language Service to solve the performance problem, combined with the syntax highlighting of the package you suggested (syntax highlighting is include now), and can now handle the work smoothly.

It is worth mentioning that it supports Pug, and built-in html to pug conversion tool.

@sirikon Not really, from the cpuprofile it’s another perf issue. Opening new issues makes it easier for me to see which perf issues I fixed and which are not.

@octref I have same problem

  • Platform: macOS 10.14.1
  • Vetur version: 0.21.1
  • VS Code version: 1.36.1

when I scroll up and down, the cpu usage would up tp 100%

uninstall vetur will be normal

image

here is the cpu profile CPU-20190807T162515.cpuprofile.zip

I fixed #1264 and will publish a new version to benefit others.

I added instructions for https://github.com/vuejs/vetur/blob/master/.github/PERF_ISSUE.md. If you still have perf issues with Vetur, please open new issues with profiles.

@petternordholm Thanks again for your help. One last question: Does your change in getScriptFileNames make any difference in performance for you?

Also here’s a guide to profiling VLS: https://github.com/vuejs/vetur/blob/master/.github/PERF_ISSUE.md#profiling. It would help a lot if anyone else could attach their profile to this issue.

Same here, after opening a Vue project it immediately goes to >300% CPU.

Still not fixed even with TypeScript 3.3

I’m not using TypeScript, so I think the issue goes beyond that.

Could this be a Mac-specific issue? Is anyone seeing this on Windows?

I know there are lots of people that use VS Code on a Mac to edit Vue projects. It’s hard to believe this isn’t affecting a lot of people now. Really serious!