zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
46.94k stars 2.7k forks source link

High CPU / power consumption with Groovy language server + others (MacOS Intel FPS) #16729

Closed amaridev closed 1 week ago

amaridev commented 3 weeks ago

Check for existing issues

Describe the bug / provide steps to reproduce it

Hi, I started to use zed recently and like it pretty much so far. I work a lot with Groovy and Jenkins Pipelines and face some issue with the Groovy plugin, I assume.

I already noticed that the syntax checking and auto format doesn't really work on Groovy files for me. Now I found that Zed sucked my battery empty in less than 2 hours. I am working on a Macbook Pro M1 Max.

I am not sure yet if it's a bug or some problem just on my machine. Hope to get some help figuring out where the issue is.

Environment

Zed: v0.149.5 (Zed) OS: macOS 14.4.0 Memory: 32 GiB Architecture: aarch64

If applicable, add mockups / screenshots to help explain present your vision of the feature

Screenshot 2024-08-23 at 09 09 16
USER         PID  %CPU %MEM      VSZ    RSS   TT  STAT STARTED      TIME COMMAND
me 64071  99.4  2.0 422213136 682768   ??  R     1:32PM 305:29.04 java -jar /Users/me/Library/Application Support/Zed/extensions/work/groovy/groovy-language-server-2884e64/groovy-langu

If applicable, attach your Zed.log file to this issue.

Zed.log

2024-08-23T07:06:49.767049Z [INFO] ========== starting zed ==========
2024-08-23T07:06:49.769293Z [INFO] Opening main db
2024-08-23T07:06:49.771388Z [INFO] Using git binary path: Some("/Applications/Zed.app/Contents/MacOS/git")
2024-08-23T07:06:49.900457Z [INFO] initializing context server client
2024-08-23T07:06:49.900815Z [INFO] Registering built-in prompt template: content_prompt
2024-08-23T07:06:49.901269Z [INFO] Registering built-in prompt template: edit_workflow
2024-08-23T07:06:49.901599Z [INFO] Registering built-in prompt template: step_resolution
2024-08-23T07:06:49.90204Z [INFO] Registering built-in prompt template: terminal_assistant_prompt
2024-08-23T07:06:49.902292Z [INFO] No prompt template overrides directory found at /Users/maya.scheu/.config/zed/prompt_overrides. Using built-in prompts.
2024-08-23T07:06:49.903934Z [INFO] extensions updated. loading 10, reloading 0, unloading 0
2024-08-23T07:06:49.906914Z [INFO] performance metrics display disabled
2024-08-23T07:06:49.94019Z [WARN] request completed with error: failed to connect to the server
2024-08-23T07:06:49.940351Z [WARN] request completed with error: failed to connect to the server
2024-08-23T07:06:49.940448Z [WARN] request completed with error: failed to connect to the server
2024-08-23T07:06:49.940543Z [WARN] request completed with error: failed to connect to the server
2024-08-23T07:06:49.94233Z [WARN] request completed with error: failed to connect to the server
2024-08-23T07:06:49.942405Z [INFO] Opening main db
2024-08-23T07:06:49.942468Z [WARN] request completed with error: failed to connect to the server
2024-08-23T07:06:49.94254Z [WARN] request completed with error: failed to connect to the server
2024-08-23T07:06:49.94261Z [WARN] request completed with error: failed to connect to the server
2024-08-23T07:06:49.942671Z [WARN] request completed with error: failed to connect to the server
2024-08-23T07:06:49.944152Z [WARN] request completed with error: failed to connect to the server
2024-08-23T07:06:49.946136Z [WARN] request completed with error: failed to connect to the server
2024-08-23T07:06:49.948402Z [WARN] request completed with error: failed to connect to the server
2024-08-23T07:06:49.949423Z [INFO] building git repository, `.git` path in the worktree: ".git"
2024-08-23T07:06:50.107595Z [INFO] set status on client 0: Authenticating
2024-08-23T07:06:50.110218Z [INFO] Opening main db
2024-08-23T07:06:50.110291Z [WARN] request completed with error: failed to connect to the server
2024-08-23T07:06:50.111593Z [INFO] time to first window draw: 345.104167ms
2024-08-23T07:06:50.112028Z [WARN] request completed with error: failed to connect to the server
2024-08-23T07:06:50.112115Z [WARN] request completed with error: failed to connect to the server
2024-08-23T07:06:50.114065Z [INFO] set status on client 209727: Connecting
2024-08-23T07:06:50.114313Z [INFO] Node runtime install_if_needed
2024-08-23T07:06:50.115784Z [INFO] Opening main db
2024-08-23T07:06:50.13125Z [INFO] Initializing default prettier with plugins {}
2024-08-23T07:06:50.132142Z [WARN] request completed with error: failed to connect to the server
2024-08-23T07:06:50.144327Z [ERROR] No worktree for path: "/Users/maya.scheu/.config/zed/settings.json"
2024-08-23T07:06:50.16959Z [INFO] Initializing default prettier with plugins {}
2024-08-23T07:06:50.173683Z [WARN] request completed with error: failed to connect to the server
2024-08-23T07:06:50.228518Z [INFO] Initializing default prettier with plugins {}
2024-08-23T07:06:50.228604Z [INFO] starting language servers for Groovy: 
2024-08-23T07:06:50.22967Z [INFO] Initializing default prettier with plugins {}
2024-08-23T07:06:50.229754Z [INFO] starting language servers for Groovy: 
2024-08-23T07:06:50.230491Z [INFO] Initializing default prettier with plugins {}
2024-08-23T07:06:50.230564Z [INFO] starting language servers for Groovy: 
2024-08-23T07:06:50.231197Z [INFO] Initializing default prettier with plugins {}
2024-08-23T07:06:50.231273Z [INFO] starting language servers for Groovy: 
2024-08-23T07:06:50.232453Z [INFO] Initializing default prettier with plugins {}
2024-08-23T07:06:50.232542Z [INFO] starting language servers for Groovy: 
2024-08-23T07:06:50.233132Z [INFO] Initializing default prettier with plugins {}
2024-08-23T07:06:50.23319Z [INFO] starting language servers for Groovy: 
2024-08-23T07:06:50.233336Z [INFO] Initializing default prettier with plugins {}
2024-08-23T07:06:50.233385Z [INFO] Initializing default prettier with plugins {}
2024-08-23T07:06:50.233428Z [INFO] starting language servers for Groovy: 
2024-08-23T07:06:50.233476Z [INFO] starting language servers for Groovy: 
2024-08-23T07:06:50.233512Z [INFO] starting language servers for Groovy: 
2024-08-23T07:06:50.233555Z [INFO] starting language servers for Groovy: 
2024-08-23T07:06:50.233603Z [INFO] starting language servers for Groovy: 
2024-08-23T07:06:50.233646Z [INFO] starting language servers for Groovy: 
2024-08-23T07:06:50.2384Z [WARN] request completed with error: failed to connect to the server
2024-08-23T07:06:50.265558Z [INFO] starting language server. binary path: "/Users/maya.scheu/Library/Application Support/Zed/node/node-v22.5.1-darwin-arm64/bin/node", working directory: "/", args: ["/Users/maya.scheu/Library/Application Support/Zed/copilot/copilot-v0.5.0/dist/agent.js", "--stdio"]
2024-08-23T07:06:50.381445Z [INFO] connected to rpc endpoint https://collab.zed.dev/rpc
2024-08-23T07:06:50.392573Z [INFO] set environment variables from shell:/bin/zsh, path:/Users/maya.scheu/.krew/bin:/opt/homebrew/opt/gawk/libexec/gnubin:/opt/homebrew/opt/gnu-sed/libexec/gnubin:/opt/homebrew/lib/ruby/gems/3.2.0/bin:/opt/homebrew/opt/ruby/bin:/opt/homebrew/opt/libpq/bin:/opt/homebrew/opt/curl/bin:/opt/homebrew/opt/curl/bin:/opt/homebrew/opt/grep/libexec/gnubin:/Users/maya.scheu/.nvm/versions/node/v20.11.0/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin://Applications/Topaz Photo AI.app/Contents/Resources/bin:/Library/Apple/usr/bin:/usr/local/MacGPG2/bin:/Applications/Wireshark.app/Contents/MacOS:/usr/local/share/dotnet:~/.dotnet/tools:/Users/maya.scheu/.krew/bin:/opt/homebrew/opt/gawk/libexec/gnubin:/opt/homebrew/opt/gnu-sed/libexec/gnubin:/opt/homebrew/lib/ruby/gems/3.2.0/bin:/opt/homebrew/opt/ruby/bin:/opt/homebrew/opt/libpq/bin:/opt/homebrew/opt/curl/bin:/opt/homebrew/opt/grep/libexec/gnubin:/Users/maya.scheu/.nvm/versions/node/v20.11.0/bin:/Users/maya.scheu/.sdkman/candidates/maven/current/bin:/Users/maya.scheu/.sdkman/candidates/java/current/bin:/Users/maya.scheu/.sdkman/candidates/groovy/current/bin:/Users/maya.scheu/.sdkman/candidates/gradle/current/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/maya.scheu/Library/Python/3.9/bin:/Users/maya.scheu/.orbstack/bin:/Users/maya.scheu/Library/Application Support/JetBrains/Toolbox/scripts:/Users/maya.scheu/.orbstack/bin:/Users/maya.scheu/Library/Application Support/JetBrains/Toolbox/scripts
2024-08-23T07:06:50.506817Z [INFO] Language server with id 0 sent unhandled notification LogMessage:
{
  "level": 0,
  "message": "[DEBUG] [agent] [2024-08-23T07:06:50.504Z] Agent service starting",
  "metadataStr": "[DEBUG] [agent] [2024-08-23T07:06:50.504Z]",
  "extra": [
    "Agent service starting"
  ]
}
2024-08-23T07:06:50.508061Z [INFO] Language server with id 0 sent unhandled notification client/registerCapability:
{
  "registrations": [
    {
      "id": "6e877002-2468-486e-bd36-c57836bc78ef",
      "method": "workspace/didChangeWorkspaceFolders",
      "registerOptions": {}
    }
  ]
}
2024-08-23T07:06:50.733609Z [INFO] Initializing default prettier with plugins {}
2024-08-23T07:06:50.733668Z [INFO] Initializing default prettier with plugins {}
2024-08-23T07:06:50.733709Z [INFO] starting language servers for Groovy: groovy
2024-08-23T07:06:50.733761Z [INFO] starting language server "groovy", path: "/Users/maya.scheu/workspace/ident-ai/ident-ai_jenkins-shared/", id: 1
2024-08-23T07:06:50.733824Z [INFO] starting language servers for Groovy: groovy
2024-08-23T07:06:50.733858Z [INFO] starting language servers for Groovy: groovy
2024-08-23T07:06:50.733893Z [INFO] starting language servers for Groovy: groovy
2024-08-23T07:06:50.733927Z [INFO] starting language servers for Groovy: groovy
2024-08-23T07:06:50.733961Z [INFO] starting language servers for Groovy: groovy
2024-08-23T07:06:50.734916Z [WARN] request completed with error: failed to connect to the server
2024-08-23T07:06:50.781877Z [INFO] add connection to peer
2024-08-23T07:06:50.781947Z [INFO] add_connection;
2024-08-23T07:06:50.781984Z [INFO] waiting for server hello
2024-08-23T07:06:50.790366Z [INFO] got server hello
2024-08-23T07:06:50.790444Z [INFO] set status to connected (connection id: ConnectionId { owner_id: 0, id: 0 }, peer id: PeerId { owner_id: 499, id: 279372 })
2024-08-23T07:06:50.79053Z [INFO] set status on client 209727: Connected { peer_id: PeerId { owner_id: 499, id: 279372 }, connection_id: ConnectionId { owner_id: 0, id: 0 } }
2024-08-23T07:06:50.831535Z [INFO] Language server with id 0 sent unhandled notification LogMessage:
{
  "level": 0,
  "message": "[DEBUG] [agent] [2024-08-23T07:06:50.825Z] Telemetry initialized",
  "metadataStr": "[DEBUG] [agent] [2024-08-23T07:06:50.825Z]",
  "extra": [
    "Telemetry initialized"
  ]
}
2024-08-23T07:06:50.924377Z [INFO] starting language server. binary path: "/Users/maya.scheu/Library/Application Support/Zed/extensions/work/groovy/groovy-language-server-2884e64/groovy-language-server-macOS/groovy_language_server_wrapper", working directory: "/Users/maya.scheu/workspace/ident-ai/ident-ai_jenkins-shared/", args: []
2024-08-23T07:07:07.665163Z [INFO] stopping language server groovy
2024-08-23T07:07:07.666232Z [ERROR] oneshot canceled
2024-08-23T07:07:07.666337Z [INFO] starting language servers for Groovy: groovy
2024-08-23T07:07:07.666403Z [INFO] starting language server "groovy", path: "/Users/maya.scheu/workspace/ident-ai/ident-ai_jenkins-shared/", id: 2
2024-08-23T07:07:07.66677Z [INFO] starting language server. binary path: "/Users/maya.scheu/Library/Application Support/Zed/extensions/work/groovy/groovy-language-server-2884e64/groovy-language-server-macOS/groovy_language_server_wrapper", working directory: "/Users/maya.scheu/workspace/ident-ai/ident-ai_jenkins-shared/", args: []
2024-08-23T07:10:16.351996Z [INFO] Initializing default prettier with plugins {}
2024-08-23T07:10:16.352092Z [INFO] Initializing default prettier with plugins {}
2024-08-23T07:10:16.352149Z [INFO] starting language servers for Groovy: groovy
2024-08-23T07:10:16.352207Z [INFO] starting language servers for Groovy: groovy
2024-08-23T07:10:16.352264Z [INFO] starting language servers for Groovy: groovy
2024-08-23T07:10:16.352318Z [INFO] starting language servers for Groovy: groovy
2024-08-23T07:10:16.352372Z [INFO] starting language servers for Groovy: groovy
2024-08-23T07:10:16.352426Z [INFO] starting language servers for Groovy: groovy
2024-08-23T07:10:16.355746Z [WARN] request completed with error: failed to connect to the server

SchiavoAnto commented 3 weeks ago

Since a couple of days ago, I'm having similar issues. I mainly use Zed to write C# (with the OnmiSharp plugin), so I think this is a more general problem rather that an issue with the Groovy LSP. Zed spikes CPU usage when doing anything and it becomes very laggy when moving the cursor with the arrow keys. I think this started with 0.149.3, as I did not have any issues before.

Edit: adding system information Zed version: 0.149.5 (5321b10aa41e2ac0603c7a6fc99ba1ae9421b460) OS: macOS Ventura 13.6.7 RAM: 8GB Architecture: x86-64

d-shah8 commented 3 weeks ago

I'm having similar issues too, I disabled language servers and still the consumption remained high. I rolled back to 0.148.0 which doesn't seem to have the issue.

System info: Zed version: Preview 0.150.3 (but tried 0.149.3 too) OS: macOS Sonoma 14.6.1 RAM: 16 GB Intel i5

amaridev commented 2 weeks ago

@SchiavoAnto Yes you might be right, that it affects more languages than I thought in the beginning. I started to notice the same issues with Go.

mdelete commented 2 weeks ago

Same here with rust. With the latest releases, my Macbook went in full overdrive, even with the lid closed, three times so far, completely draining the battery in the process. I have to quit zed now before closing the lid. It is not the zed process creating the load though, always processes like kernel_task and Quick Look Satellite. But only if zed is running.

SchiavoAnto commented 2 weeks ago

@mdelete Oh yeah the overheating with the lid closed happened to me too. I was using Zed and closed the laptop, like I always do, and found it very very hot and the battery was almost completely flat. I noticed too that it's not the Zed process directly causing this, but only happens when using Zed.

piechologist commented 2 weeks ago

Since Zed 0.149 my MacBook was getting hot, even with no LS running.

I tried to leave Zed open with just a small txt file and all my personal settings removed and it's draining the battery in no time. Activity Monitor shows relatively high CPU + GPU usage.

I went back to Zed 0.148 and this issue disappeared. So, there must be a serious regression between 0.148 and 0.149.

notpeter commented 1 week ago

There was quite a bit that happened between v0.148.x and v0.149.x (277 commits) as it was leading up the Zed.ai launch. Similarly a lot that has happened in the intervening time [between v0.149.x and v0.151.x] (200 commits).

Are folks still seeing this issue with current releases (Zed Preview v0.151.x)?

If yes, would anyone experiencing this be willing to do the git bisect from a working build to v0.149.x to help track down the offending commit?

chengdujin commented 1 week ago

The power consumption on my Mac is shocking. Removing Zed/Zed Preview for now.

piechologist commented 1 week ago

Just tried 0.151.1, the Mac ran hot within 30 minutes.

I left Zed running with an empty window. No other apps were running except Activity Monitor. Repeated test with Zed Preview.

Activity Monitor is confusing:

Zed 0.148: CPU Time 55s, GPU Time 11s WindowServer process: CPU Time 53s, GPU Time 26s

Zed 0.151 CPU Time 55s, GPU Time 10s WindowServer process: CPU Time 1m06s, GPU Time 17s

There's almost no difference! I don't even know how to measure the power drain. If I didn't trust you I'd say you're running a hidden process to train your next AI model 😉 😂.

I'm happy to investigate as long as I don't need to build Zed (and install all the tools to do that).

d-shah8 commented 1 week ago

@notpeter I can build from source and give that a try but like @piechologist said I have no idea how to measure for the bad commit apart from feeling my Mac and listening to the fans running. I also don't see any differences between versions in Activity Monitor. Any other ideas would be appreciated!

hmilkovi commented 1 week ago

Hi, just to make basic triage:

  1. How does auto update work, does it pull intel for intel macs or universal binary? I have how installed explicit Intel again and I'm monitoring it.
  2. I'm on Intel, are there any major differences M vs Intel series binaries?
piechologist commented 1 week ago

Browsing through this issue and adding my machine:

dhutaryan commented 1 week ago

I have the similar issue using js/ts

0.150.4

d-shah8 commented 1 week ago

@notpeter it took longer than I thought but this was my experience with different commits on my Mac

$ git bisect log
# bad: [7155d2c45fea97cdff7c97bfe3c7ffb5962cc17d] assistant: Set default provider to zed.dev (#16454)
# good: [69fb9b9bfab03a457185b688ef5228a87f9c69a7] assistant: Adjust terms of service notice (#16235)
git bisect start 'v0.149.3' 'v0.149.0-pre'
# good: [a3a6ebcf31a95d41bccd33334016eacdb4713615] Small fixes to content generation prompt (#16359)
git bisect good a3a6ebcf31a95d41bccd33334016eacdb4713615
# bad: [86efde4b76989bfa24a54f90491c2d91058d9373] Fixed bugs in workflow step preview (#16445)
git bisect bad 86efde4b76989bfa24a54f90491c2d91058d9373
# good: [9ef3306f5552d0149a5a951f7b1a0ba6509ce2ea] Add feature flags to seed script (#16385)
git bisect good 9ef3306f5552d0149a5a951f7b1a0ba6509ce2ea
# good: [c9c5eef8f23ef90dae5d0e19999b42172b7ec685] Improve dev experience for built-in prompts (#16413)
git bisect good c9c5eef8f23ef90dae5d0e19999b42172b7ec685
# good: [6f93b42ecb239e9c494a1f969a183b30787833a3] docs: Fix example extension directory structure (#16424)
git bisect good 6f93b42ecb239e9c494a1f969a183b30787833a3
# bad: [b9176fe4bbd34e96e85528b382e2a8f5c0006748] Add custom icon for Anthropic hosted models (#16436)
git bisect bad b9176fe4bbd34e96e85528b382e2a8f5c0006748
# bad: [11753914d750cb62588cf709ab0acb036ccba1f9] Add a setting to show time to first window draw and frames per second in status bar (#16422)
git bisect bad 11753914d750cb62588cf709ab0acb036ccba1f9
# first bad commit: [11753914d750cb62588cf709ab0acb036ccba1f9] Add a setting to show time to first window draw and frames per second in status bar (#16422)
notpeter commented 1 week ago

You are a rockstar @d-shah8. https://github.com/zed-industries/zed/commit/11753914d750cb62588cf709ab0acb036ccba1f9 is:

Which added some performance counters. It should all be gated behind performance.show_in_status_bar: true and otherwise a no-op. I'll take a look.

notpeter commented 1 week ago

I'd like to identify if there is a common pattern of hardware impacted by this.

If you are experiencing this, please run the following and paste with a comment below and I'll collate the results and hide the comments.

system_profiler SPDisplaysDataType SPSoftwareDataType SPHardwareDataType |grep -e Model -e Memory: -e Metal -e macOS -e Chip -e '^[A-Z.]' 
piechologist commented 1 week ago
Graphics/Displays:
      Chipset Model: Intel HD Graphics 515
      Metal Family: Supported, Metal GPUFamily macOS 2
Software:
      System Version: macOS 12.7.6 (21H1320)
      Secure Virtual Memory: Enabled
Hardware:
      Model Name: MacBook
      Model Identifier: MacBook9,1
      Memory: 8 GB
SchiavoAnto commented 1 week ago
Graphics/Displays:
      Chipset Model: Intel Iris Plus Graphics 640
      Metal Support: Metal 3
Software:
      System Version: macOS 13.6.7 (22G720)
      Secure Virtual Memory: Enabled
Hardware:
      Model Name: MacBook Pro
      Model Identifier: MacBookPro14,1
      Memory: 8 GB
d-shah8 commented 1 week ago
Graphics/Displays:
      Chipset Model: Intel Iris Plus Graphics 655
      Metal Support: Metal 3
Software:
      System Version: macOS 14.6.1 (23G93)
      Secure Virtual Memory: Enabled
Hardware:
      Model Name: MacBook Pro
      Model Identifier: MacBookPro15,2
      Memory: 16 GB
mrnugget commented 1 week ago

Thanks @d-shah8. @bennetbo and I created a build (in https://github.com/zed-industries/zed/actions/runs/10735702994?pr=17485) for you all to try out:

In that build, the FPS counter code has been reverted (we couldn't spot an obvious reason for why it would decrease performance).

Can you try out the Intel build and see if it fixes the problem?

SchiavoAnto commented 1 week ago

@mrnugget I am trying the Intel build and it looks like the issue is fixed

d-shah8 commented 1 week ago

@mrnugget yep issue seems fixed with that Intel build for me too.

mdelete commented 1 week ago

Ahhh... silence of the fans. Seems to fixed for me too (Intel build).

piechologist commented 1 week ago

Intel build looks good for me too. Thanks a lot!

golovinengineer commented 1 week ago

x86/Intel build looks very well. I wrote in a pull request comments at first, sorry.

notpeter commented 1 week ago

This fix is available in Zed Preview v0.152.1 and Zed Stable v0.151.2.

Thanks for everyone who helped track this down and please accept our apologies for the two weeks of battery drain.

@amaridev Apologies for hijacking your issue. As the original reporter you reported this on aarch64 while most of the participants in this discussion are seeing what I believe is an Intel x86_64 specific issue.

If these builds don't solve your problem, please open a clean issue so we can track that separately. Thanks all!