language-tools icon indicating copy to clipboard operation
language-tools copied to clipboard

high cpu usage

Open think2011 opened this issue 3 years ago • 6 comments

Snipaste_2022-04-19_15-51-00 Issue Type: Bug

I turned off all plugins except prisma, I use nx monorepo and tried to create minimal reproduction, but failed to reproduce.

add more details later.

Extension version: 3.12.0 VS Code version: Code 1.66.2 (dfd34e8260c270da74b5c2d86d61aee4b6d56977, 2022-04-11T07:47:29.396Z) OS version: Darwin arm64 21.3.0 Restricted Mode: No

System Info
Item Value
CPUs Apple M1 (8 x 24)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
oop_rasterization: enabled
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
Load (avg) 7, 11, 11
Memory (System) 16.00GB (0.07GB free)
Process Argv --crash-reporter-id a7b608fd-1ae2-4400-ba59-15416892bf9e
Screen Reader yes
VM 0%
A/B Experiments
vsliv368:30146709
vsreu685:30147344
python383cf:30185419
vspor879:30202332
vspor708:30202333
vspor363:30204092
pythonvspyl392:30443607
pythontb:30283811
pythonptprofiler:30281270
vshan820:30294714
vstes263cf:30335440
vscoreces:30445986
pythondataviewer:30285071
vscod805:30301674
pythonvspyt200:30340761
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593:30376534
vsc1dst:30438360
pythonvs932:30410667
wslgetstarted:30449410
pythonvsnew555:30457759
vscscmwlcmt:30465135

think2011 avatar Apr 19 '22 07:04 think2011

After I disabe Prisma fileWatcher, CPU usage is back to normal quickly.

#1118 Snipaste_2022-04-19_16-05-41

think2011 avatar Apr 19 '22 08:04 think2011

Maybe some directories should be disabled by default, here are the settings I've had performance issues with vscode in the past.

  "search.followSymlinks": false,
  "files.exclude": {
    "**/.git": true,
    "**/.svn": true,
    "**/.hg": true,
    "**/CVS": true,
    "**/.DS_Store": true,
    "**/tmp": true,
    "**/node_modules": true,
    "**/bower_components": true,
    "**/dist": true
  },
  "files.watcherExclude": {
    "**/.git/objects/**": true,
    "**/.git/subtree-cache/**": true,
    "**/node_modules/**": true,
    "**/tmp/**": true,
    "**/bower_components/**": true,
    "**/dist/**": true
  },

think2011 avatar Apr 19 '22 08:04 think2011

Having this issue as well. Immediately after installing this extension my CPU usage spiked to maximum, showing electron as the offender. I let it run at max for 3-5 min. After disabling the extension, CPU usage quickly returned to normal.

Extension version v3.12.0

otus-jfortman avatar Apr 21 '22 14:04 otus-jfortman

I have the same issue. It occurs both on Insider and stable versions of the extension. CPU instantly goes crazy when the extension is installed.

Seems to be ok when filewatcher is disabled.

ivoljubicic avatar May 06 '22 12:05 ivoljubicic

If anyone can give us a repository that can reproduce the issue that would be very helpful. We know this is happening, but we just do not have a reliable way to reproduce and thus debug it.

janpio avatar May 06 '22 16:05 janpio

I can't sorry. It's not my personal project.

My equipment is the intel version of Macbook Pro.

If anyone can give us a repository that can reproduce the issue that would be very helpful. We know this is happening, but we just do not have a reliable way to reproduce and thus debug it.

ivoljubicic avatar May 06 '22 19:05 ivoljubicic

Hi! @ivoljubicic @otus-jfortman @think2011 @dannylee1020

I created a PR to fix the file watcher issue, I'm happy to report that on my computer (macOS m1) it's now fixed. (CPU goes from ~100% previously to 0%)

Could you confirm it's also fixed for you as well?

Follow these instructions

First, confirm that the CPU usage is high using the Prisma extension from the VS Code marketplace

  • Open your project using Prisma
  • If you disabled the Prisma File Watcher functionality, enable it again from the command palette: Screenshot 2022-09-08 at 22 09 12
  • Open the schema.prisma file from your project
  • Use "Open Process Explorer" from VS Code' menu or open the OS Activity monitor Screenshot 2022-09-08 at 22 07 22
  • Note / screenshot the CPU usage for the extension host above the Prisma extension process for the explorer or for the Activity Monitor, the Code Helper (Renderer) value and share it at the end

Second, confirm that with the new extension the CPU usage is low using a special build from my PR

Note: only the file watcher logic was changed.

  • Uninstall any Prisma extension installed (uninstall is preferred as only disabling might interfere in some ways)
  • Download https://github.com/prisma/language-tools/blob/artifacts/pull-request-artifacts/pr1243-prisma.vsix?raw=true
  • Click "Install from VSIX" from this button (screenshot) or command palette and select the pr1243-prisma.vsix file Screenshot 2022-09-08 at 22 05 33
  • Restart the VS Code application
  • Open the schema.prisma file from your project
  • Use "Open Process Explorer" from VS Code' menu or open the OS Activity monitor Screenshot 2022-09-08 at 22 07 22
  • Note / screenshot the CPU usage for the extension host above the Prisma extension process for the explorer or for the Activity Monitor, the Code Helper (Renderer) value and share it at the end

Third, if you have a TypeScript project, confirm that the file watcher works and that the types are refreshed

  • Open a TypeScript file from your project where you have Prisma Client queries like await prisma.user.findMany()
  • Open the schema.prisma file from your project
  • Both should have no errors
  • Edit the schema.prisma file and delete all the models (only keep the datasource & generator blocks)
  • Run npx prisma generate
  • In your TypeScript file, you should now instantly see a Type Error that should look like the following Screenshot 2022-09-08 at 22 20 12
  • Undo the changes in your schema.prisma
  • Run npx prisma generate
  • The Type Error(s) in the TypeScript file should be gone now

Please share something like the following: I tested on ... (macOS m1, Windows, Linux....)

  1. Current extension: screenshot showing ~91% CPU (Note: CPU is only reported on the aggregated top line for some reason) current_filewatcher_enabled_cpu_at_100ish
  2. Using pr1243-prisma.vsix, screenshot after showing ~0% CPU usage 🎊 new_filewatcher_enabled_cpu_at_0
  3. The typings were updated successfully after npx prisma generate, a Type Error was visible ✅

Thank you in advance 💚 Note: I'm waiting for some feedback before we switch to this new low CPU file watcher in a stable release on VS Code marketplace.

Jolg42 avatar Sep 08 '22 20:09 Jolg42

The fix is now in the latest 4.4.0 version on the marketplace https://marketplace.visualstudio.com/items?itemName=Prisma.prisma 🎊

For those who disabled the File Watcher functionality, you can enable it again.

Jolg42 avatar Sep 28 '22 08:09 Jolg42