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

extensionHost 100% CPU usage due to Prisma

Open gkossakowski opened this issue 2 years ago • 6 comments

Type: Bug

Reproduce:

  1. Open https://github.com/redwoodjs/redwood-tutorial in VSCode
  2. Open schema.prisma
  3. Watch 100% CPU usage that never goes down

Extension version: 4.1.0 VS Code version: Code 1.70.0 (da76f93349a72022ca4670c1b84860304616aaa2, 2022-08-04T04:39:20.716Z) OS version: Darwin arm64 21.6.0 Modes:

System Info
Item Value
CPUs Apple M1 Pro (10 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
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) 10, 9, 8
Memory (System) 32.00GB (1.17GB free)
Process Argv . --crash-reporter-id e55ceadf-1d93-4a73-8748-610272349188
Screen Reader no
VM 0%
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492cf:30256860
vslsvsres303:30308271
pythonvspyl392:30443607
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
vscorecescf:30445987
pythondataviewer:30285071
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593:30376534
vsc1dst:30438360
pythonvs932:30410667
wslgetstarted:30449410
vscscmwlcmt:30465135
cppdebug:30492333
vscaac:30438847
pylanb8912:30529769
vsclangdc:30486549
c4g48928:30535728
hb751961:30541207
dsvsc012:30540252

gkossakowski avatar Aug 08 '22 15:08 gkossakowski

Prisma ext was pinpointed with the Extension Bisect.

gkossakowski avatar Aug 08 '22 16:08 gkossakowski

Is this reproducible? Does it go away if you disable the File Watcher in the Prisma Extension settings?

janpio avatar Aug 08 '22 16:08 janpio

It is 100% reproducible for me. Disabling File Watcher in the Prisma Extension settings makes the problem go away. Is disabling that setting safe to use as a work-around for now?

gkossakowski avatar Aug 08 '22 17:08 gkossakowski

Definitely. It might surface a bug/problem in the Typescript server though, after you prisma generate it might not pick up the new types and hence underline some usage of prisma. in your code red. That is what the file watcher is trying to avoid by restarting the TS Server automatically, but you can also do that manually if it happens.

janpio avatar Aug 08 '22 18:08 janpio

Got it. Thanks for the explanation. File Watcher spinning 100% cpu indefinitely does still sound like a bug?

gkossakowski avatar Aug 08 '22 18:08 gkossakowski

Yes, there should be multiple already.

janpio avatar Aug 08 '22 23:08 janpio

Hi! @gkossakowski @rstrand @thgh

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