forcedotcom / salesforcedx-vscode

Salesforce Extensions for VS Code
https://developer.salesforce.com/tools/vscode
BSD 3-Clause "New" or "Revised" License
947 stars 405 forks source link

Extension causes high cpu load #1100

Closed cipherstream closed 5 years ago

cipherstream commented 5 years ago

:warning: Make sure to attach this file from your home-directory: C:\Users\chadh\salesforce.salesforcedx-vscode-core-unresponsive.cpuprofile.txt :warning:

Find more details here: https://github.com/Microsoft/vscode/wiki/Explain:-extension-causes-high-cpu-load

cipherstream commented 5 years ago

Requested Attachment: salesforce.salesforcedx-vscode-core-unresponsive.cpuprofile.txt

praksb commented 5 years ago

@cipherstream Can you share more information on what operation you were performing when you observe the high cpu load? Is it during loading a new project or editing a file or applying a refactoring? Does the cpu load come down after sometime or does it just continue to stay high?

It is possible that the Apex LSP which is a Java process might be the source of high CPU. In that case, can you also share a thread dump that would help us identify the problem. You can use jstack to collect this information. Here is some info on taking thread dumps:

https://blog.fastthread.io/2016/06/06/how-to-take-thread-dumps-7-options/

nkadis commented 5 years ago

Summary

I've updated the extension to the latest version (45.3.0), but still have the same problem I posted about in issue #968.

Steps To Reproduce:

  1. Open VS Code.
  2. Open a .cls file (possibly a large one - I used a ~3000 line one, but might also happen with smaller ones, not really sure)
  3. Start editing the file

Expected result

Nothing in particular, just normal editing, syntax highlighting, autocomplete, references and definitions, etc..

Actual result

CPU usage ~300%.

Additional information

Below is the cpuprofile and thread dump of the Java process that causes extreme CPU usage when editing a .cls file:

CPU Profile Thread Dump


This might not be related to the above example, but might also be helpful. Upon starting VS Code, while "Scanning user-defined types", there seems to be a spike in the CPU usage, but then falls back down when the scanning ends. Below is a gif of the ALS output & CPU usage and the cpuprofile:

Startup CPU Profile


VS Code Version: Version 1.31.1 (1.31.1) SFDX CLI Version: sfdx-cli/6.54.4-c01dcc69db (darwin-x64) node-v8.9.4 OS and version: macOs Mojave Version 10.14.3

praksb commented 5 years ago

@nkadis Thank you for uploading the thread dump. Apex LSP does some work in the background to process the edits that you are making to a doc that would result in a CPU spike which is expected. Do you see the CPU spike and then fall down a few seconds after your edit is complete? One of the issues we were seeing previously was that the CPU spikes and stays high for much longer (more than a couple of minutes) on an edit and the fix we released recently addressed that. Note that we are also continuing to make some tweaks to handling edits more efficiently so you should continue to see some improvements in the coming few weeks.

The spike in CPU usage when starting VS Code is also expected since we start off by compiling and indexing all the classes and triggers. CPU usage should fall once the scanning/indexing is complete though.

nkadis commented 5 years ago

@praksb Thank you for the quick reply and detailed explanation.

Regarding your comment:

Do you see the CPU spike and then fall down a few seconds after your edit is complete?

Unfortunately, the CPU spike doesn't fall while I'm editing. From what I've experienced, and based off of your reply, I can say that once I start making a few consecutive edits I get errors about unmatched cancel notifications like the one below, and the CPU usage cranks up to spikes between ~120% and ~300%. I haven't tried leaving it do its thing to see if it actually stops because the laptop heats up really fast to the point where you could cook an egg where the CPU is.

org.eclipse.lsp4j.jsonrpc.RemoteEndpoint handleCancellation WARNING: Unmatched cancel notification for request id 636

the CPU spikes and stays high for much longer (more than a couple of minutes) on an edit and the fix we released recently addressed that

It does still stay high for more than a couple of minutes. I would say I've left it spiked for ~10 mins with no signs of going down.

Note that we are also continuing to make some tweaks to handling edits more efficiently so you should continue to see some improvements in the coming few weeks.

Thank you so much, I'll keep an eye out for any changes. Will these tweaks come as an update to the extension?

CPU usage should fall once the scanning/indexing is complete though.

On startup, CPU usage does indeed fall after those tasks are complete.

Thanks again for the help. If you need any other information, I'll be glad to provide it asap.

praksb commented 5 years ago

@nkadis We are actively working on performance improvements to the editing experience. The changes I mentioned will come as incremental updates to the extension. I'll update this thread when the next change is released.

paul-drozd-itechart commented 5 years ago

Having the same issue

praksb commented 5 years ago

@cipherstream @nkadis @paul-drozd-itechart We just released our latest Apex extension update which has fixes to improve the performance of Apex editing experience. Please upgrade to v45.5.0 and let us know if you still run into any issues.