toitware / ide-tools

Tools for working with Toit in different IDEs
MIT License
2 stars 2 forks source link

High CPU usage on MacOS #212

Closed bpmct closed 1 year ago

bpmct commented 1 year ago

I'm seeing extremely high CPU usage on my MacOS (amd64) machine. On Linux, the extension works fine. Here are the logs from the output panel:

2023-03-19T14:50:17.591-0500    ERROR   Compiler.compiler_protocol  compiler/compiler_fs_protocol.go:135    read failed {"error": "io: read/write on closed pipe"}
github.com/toitware/toit.git/toitlsp/lsp/compiler.(*CompilerFSProtocol).HandleConn
    /Users/runner/work/toit/toit/tools/toitlsp/lsp/compiler/compiler_fs_protocol.go:135
github.com/toitware/toit.git/toitlsp/lsp/compiler.(*PipeFileServer).handleConn
    /Users/runner/work/toit/toit/tools/toitlsp/lsp/compiler/file_server_pipe.go:52

Full logs: https://gist.github.com/bpmct/ba17b88a5c43e9d6c35b48082ae7829b

floitsch commented 1 year ago

We started looking into this, but haven't made any progress yet.

floitsch commented 1 year ago

The LSP server comes with a profiler.

I just landed https://github.com/toitlang/toit/commit/d718121795c19fe5c3c382e3cf83bae31cd57483 to make it more convenient to use. Even if we can't easily reproduce this should help us figure out what's going on.

floitsch commented 1 year ago

Running the profiler with vscode:

  1. search for the settings id toitLanguageServer.command
  2. Click on "edit it settings.json"
  3. Add a call to toit.lsp. As example, here I'm using the sdk installed in my home directory /home/flo/.cache/jaguar/sdk, and store the profiles in /home/flo/tmp/lsp-profile.
    [
      "/home/flo/.cache/jaguar/sdk/bin/toit.lsp",
      "--toitc", "/home/flo/.cache/jaguar/sdk/bin/toit.compile",
      "--cpuprofile", "/home/flo/tmp/lsp-profile"
    ]
  4. Make sure your profile directory exits (mkdir -p /home/flo/tmp/lsp-profile).
  5. Restart your vscode. (For example with ctrl-shift-p, followed by Developer: Reload Window).

Every LSP server should now start to provide a profile. However, the profiles (usually) stay empty files until the process is terminated. The best way to do this is to close all Toit tabs in vscode.

floitsch commented 1 year ago

It looks like the high CPU usage was caused by another extension opening files in the background.

In this case, disabling CodeTogether solved the issue. At the moment we recommend to disable the CodeTogether extension while editing Toit code.

(I wasn't able to reproduce so I didn't file an issue against them).