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

Electron using 100% cpu with Prisma extension turned on

Open dmcd opened this issue 3 years ago • 5 comments
trafficstars

Issue Type: Bug

I am sharing a Primsa schema across multiple packages using symbolic links. I suspect the Prisma extension is having trouble with this setup.

Extension version: 3.12.0 VS Code version: Code 1.66.1 (8dfae7a5cd50421d10cd99cb873990460525a898, 2022-04-06T14:49:47.400Z) OS version: Darwin x64 21.2.0 Restricted Mode: No

System Info
Item Value
CPUs Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz (16 x 2300)
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) 2, 3, 4
Memory (System) 32.00GB (0.59GB free)
Process Argv --crash-reporter-id 9b1dda95-bb03-4b84-aa39-6cf6657594ae
Screen Reader no
VM 0%
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
pythonvspyl392:30443607
pythontb:30283811
pythonvspyt551cf:30345471
pythonptprofiler:30281270
vsdfh931cf:30280410
vshan820:30294714
vstes263:30335439
vscorecescf:30445987
pythondataviewer:30285071
vscod805:30301674
pythonvspyt200:30340761
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593cf:30376535
vsc1dst:30438360
pythonvs932:30410667
wslgetstarted:30449410
pythonvsnew555:30457759
vscscmwlcmt:30465135
pynewfile477:30463512

dmcd avatar Apr 10 '22 22:04 dmcd

Can you help us set up a minimal reproduction of your setup, optimally as a Github repo we can just clone and test it out ourselves? Thanks.

janpio avatar Apr 11 '22 19:04 janpio

@dmcd Could you try to disable the "File Watcher functionality"? Screen Shot 2021-12-21 at 13 03 51

  1. Run the Prisma: Disable the File Watcher functionality for Prisma Client command
  2. Did that solve the problem?
    • If no, try to reload VS Code.
    • If yes, please let us know, it will be helpful for us!

Jolg42 avatar May 03 '22 09:05 Jolg42

Hi @Jolg42 , yes disabling the file watcher functionality solves the problem

dmcd avatar May 03 '22 09:05 dmcd

Great to hear that it solves your issue!

We want to work on the source of the file watcher issue, we'll update you when we have news, so you could try enabling it again then 👍🏼

Jolg42 avatar May 03 '22 10:05 Jolg42

Just to mention I had the same issue, but just using prisma in one repo. Disabling the file watcher solved it for me also.

(version 4.1)

jwld avatar Jul 27 '22 09:07 jwld

Hi! @dmcd @jwld

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

Thanks! Tested on macOS Catalina 10.15.7

Current extension: Screenshot 2022-09-14 at 11 04 46

Updated extension: Screenshot 2022-09-14 at 11 08 43

We don't use TS so can't confirm the third part.

jwld avatar Sep 14 '22 10:09 jwld

Thanks for the feedback 💚

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