language-tools
language-tools copied to clipboard
Abnormal CPU usage
I have a few traces, but not sure how useful they are:
- Output of
code --status
:
With Prisma Insider v7.0.3:
Version: Code 1.48.2 (a0479759d6e9ea56afa657e454193f72aef85bd0, 2020-08-25T10:09:08.021Z) OS Version: Darwin x64 19.6.0 CPUs: Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz (12 x 2200) Memory (System): 16.00GB (1.12GB free) Load (avg): 4, 5, 3 VM: 0% Screen Reader: no Process Argv: --inspect-extensions=9993 GPU Status: 2d_canvas: enabled flash_3d: enabled flash_stage3d: enabled flash_stage3d_baseline: enabled gpu_compositing: enabled metal: disabled_off multiple_raster_threads: enabled_on oop_rasterization: disabled_off protected_video_decode: unavailable_off rasterization: enabled skia_renderer: disabled_off_ok video_decode: enabled viz_display_compositor: enabled_on viz_hit_test_surface_layer: disabled_off_ok webgl: enabled webgl2: enabledCPU % Mem MB PID Process 0 98 47408 code main 0 66 47414 gpu-process 0 16 47417 utility 0 131 47435 shared-process 0 0 47717 /bin/ps -ax -o pid=,ppid=,pcpu=,pmem=,command= 0 295 47524 window (schema.prisma — studio) 262 524 47525 extensionHost 0 82 47529 electron_node tsserver.js 0 131 47530 electron_node tsserver.js 0 82 47536 electron_node typingsInstaller.js typesMap.js 0 33 47531 electron_node cli.js 0 49 47532 electron_node server.js 0 33 47526 watcherService 0 33 47528 searchService
Workspace Stats: | Window (schema.prisma — studio) | Folder (studio): 921 files | File types: ts(233) svg(93) js(89) tsx(74) scss(72) map(55) json(34) | DS_Store(31) sh(24) html(16) | Conf files: package.json(10) tsconfig.json(6) github-actions(3) | project.json(1) webpack.config.js(1)
With Prisma (Stable?) v2.6.1:
Version: Code 1.48.2 (a0479759d6e9ea56afa657e454193f72aef85bd0, 2020-08-25T10:09:08.021Z) OS Version: Darwin x64 19.6.0 CPUs: Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz (12 x 2200) Memory (System): 16.00GB (1.18GB free) Load (avg): 4, 4, 4 VM: 0% Screen Reader: no Process Argv: --inspect-extensions=9993 GPU Status: 2d_canvas: enabled flash_3d: enabled flash_stage3d: enabled flash_stage3d_baseline: enabled gpu_compositing: enabled metal: disabled_off multiple_raster_threads: enabled_on oop_rasterization: disabled_off protected_video_decode: unavailable_off rasterization: enabled skia_renderer: disabled_off_ok video_decode: enabled viz_display_compositor: enabled_on viz_hit_test_surface_layer: disabled_off_ok webgl: enabled webgl2: enabledCPU % Mem MB PID Process 0 98 47408 code main 0 66 47414 gpu-process 0 16 47417 utility 0 131 47435 shared-process 0 0 47789 /bin/ps -ax -o pid=,ppid=,pcpu=,pmem=,command= 46 295 47740 window (schema.prisma — studio) 209 541 47743 extensionHost 0 82 47748 electron_node tsserver.js 0 147 47749 electron_node tsserver.js 0 82 47755 electron_node typingsInstaller.js typesMap.js 0 33 47751 electron_node cli.js 0 49 47752 electron_node server.js 0 33 47744 watcherService 0 33 47747 searchService
Workspace Stats: | Window (schema.prisma — studio) | Folder (studio): 921 files | File types: ts(233) svg(93) js(89) tsx(74) scss(72) map(55) json(34) | DS_Store(31) sh(24) html(16) | Conf files: package.json(10) tsconfig.json(6) github-actions(3) | project.json(1) webpack.config.js(1)
Without any Prisma Extension
Version: Code 1.48.2 (a0479759d6e9ea56afa657e454193f72aef85bd0, 2020-08-25T10:09:08.021Z) OS Version: Darwin x64 19.6.0 CPUs: Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz (12 x 2200) Memory (System): 16.00GB (1.56GB free) Load (avg): 3, 4, 3 VM: 0% Screen Reader: no Process Argv: --inspect-extensions=9993 GPU Status: 2d_canvas: enabled flash_3d: enabled flash_stage3d: enabled flash_stage3d_baseline: enabled gpu_compositing: enabled metal: disabled_off multiple_raster_threads: enabled_on oop_rasterization: disabled_off protected_video_decode: unavailable_off rasterization: enabled skia_renderer: disabled_off_ok video_decode: enabled viz_display_compositor: enabled_on viz_hit_test_surface_layer: disabled_off_ok webgl: enabled webgl2: enabledCPU % Mem MB PID Process 0 98 47408 code main 0 66 47414 gpu-process 0 16 47417 utility 0 131 47435 shared-process 0 0 47832 /bin/ps -ax -o pid=,ppid=,pcpu=,pmem=,command= 0 279 47799 window (schema.prisma — studio) 0 98 47800 extensionHost 0 82 47801 electron_node tsserver.js 0 131 47802 electron_node tsserver.js 0 82 47806 electron_node typingsInstaller.js typesMap.js 0 49 47804 electron_node server.js 0 33 47805 searchService 0 33 47809 watcherService
Workspace Stats: | Window (schema.prisma — studio) | Folder (studio): 921 files | File types: ts(233) svg(93) js(89) tsx(74) scss(72) map(55) json(34) | DS_Store(31) sh(24) html(16) | Conf files: package.json(10) tsconfig.json(6) github-actions(3) | project.json(1) webpack.config.js(1)
Notable difference is the CPU usage by extensionHost
.
- Profiling info (from VSCode) (with Prisma Insider v7.0.3): CPU-20200903T140515.170Z.cpuprofile.txt
I've been following this guide for this information: https://github.com/Microsoft/vscode/wiki/Performance-Issues
Also note that there isn't one single action that causes the slowdown, just having the extension enabled seems to be enough.
If you need any more info, please let me know!
Possibly the file watcher to get around the hanging types problem?
Same issue here
Using version 2.5.1, everything is fine.

Version 2.6.0 or 2.6.1 eats a lot of cpu

Background
I am noticing the same issue with 2.6.2, 2.6.1 and 2.6.0. Took me forever to hunt down which extension was causing the issue. I believe this is also the reason my extensions/vs code have been crashing when left open for a long time (like overnight)
Debugging
I have traced the issue back to here. https://github.com/prisma/language-tools/blob/5cef1e72ffb8c6addd052fb66d69daa865485535/packages/vscode/src/extension.ts#L70
Without this line the high CPU issue does not occur. This line was introduced in this commit. https://github.com/prisma/language-tools/commit/2979552ee371085c645ece28f857eada2f71959b
When logging the watcher
it shows that usePolling
is enabled with an interval of 100
.
This is because internally to chokidar
it checks to see if fsevents
is installed dynamically using require()
(as fsevents
is an optional dependency) and in this case fsevents
is not a dependency of the prisma
language service.
Summary
The issue is because chokidar
is polling because fsevents
is not a dependency. The easy solution is to add fsevents
as a dependency however I am not sure if fsevents
works in all environments (like Windows) as chokidar
details in their documentation that useFsEvents
is only the default on macOS. It may be a good idea to reduce the interval to avoid issues on other platforms or find another solution rather then polling.
Additional problems
I have noticed in the latest release that the TS Sever will spam restart when running ngcc
in a project with the Prisma extension installed and a prisma.schema
file open. I would greatly appreciate it if this could be avoided.
Temporary fix (macOS Only)
Run the following commands in the terminal
cd ~/.vscode/extensions/prisma.prisma-2.6.2
yarn add fsevents
Then reload VS Code
@wSedlacek Thank you for looking into this already! We have confirmed this issue and will fix it right away.
Update: This is available in our Insider extension since version 7.0.14.
This issue seems to be reoccurring in version v3.14.0 (the latest version) on MacOS. The fix mentioned here (yarn add fsevents
) also appears to solve the problem.
Issue still exists on:
Prisma Extension v4.2.0
VSCode: 1.70.2
Electron: 18.3.5
Chromium: 100.0.4896.160
Node.js: 16.13.2
V8: 10.0.139.17-electron.0
OS: Darwin arm64 21.6.0
The workaround works though:
cd ~/.vscode/extensions/prisma.prisma-4.2.0
yarn add fsevents
The workaround works though:
It needs to be applied EVERY time you upgrade Prisma 🙄... oh well
Hi there! @okomarov @andrewlague @ralvs @wSedlacek @patricknick @freddydumont @bbenezech @kahoowkh, @mrturck @aried3r @gooonzick 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:
- Open the
schema.prisma
file from your project - Use "Open Process Explorer" from VS Code' menu or open the OS Activity monitor
- 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 - 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
- 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 thedatasource
&generator
blocks) - Run
npx prisma generate
- In your TypeScript file, you should now instantly see a Type Error that should look like the following
- 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....)
- Current extension: screenshot showing ~91% CPU (Note: CPU is only reported on the aggregated top line for some reason)
- Using
pr1243-prisma.vsix
, screenshot after showing ~0% CPU usage 🎊 - 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 I am unable to reproduce the high CPU issue on prisma 4.3.1 and the corresponding extension.~~ @Jolg42
I can now confirm all of your points:
- the initial high CPU use (forgot to enable the watcher)
- the CPU use goes down with your version of the extension (the Code Helper (renderer) is also between 0-3%)
- the watcher works
@Jolg42 Hi, same here, it's all good.
I went from 161% CPU to 0% and everything refreshes as expected.
MacOS 12.5.1
2,6 GHz Intel Core i7
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.