Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

High CPU (100%+) #6894

Open
1 task done
noahlh opened this issue Jan 27, 2024 · 66 comments
Open
1 task done

High CPU (100%+) #6894

noahlh opened this issue Jan 27, 2024 · 66 comments
Labels
bug [core label] performance Feedback for performance issues, speed, memory usage, etc

Comments

@noahlh
Copy link

noahlh commented Jan 27, 2024

Check for existing issues

  • Completed

Describe the bug / provide steps to reproduce it

Launched Zed causes the overall process CPU usage to jump to 400% (two node subprocesses seem to be a majority of this), and then after a few minutes it settles down to 50-100% CPU usage. Not like what I'm seeing reports of 0-0.5%!

Environment

Zed: v0.119.20 (Zed)
OS: macOS 14.2.1
Memory: 64 GiB
Architecture: aarch64

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

Screenshot 2024-01-27 at 1 04 34 PM

If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.

If you only need the most recent lines, you can run the zed: open log command palette action to see the last 1000.

2024-01-27T21:05:36 [INFO] ========== starting zed ==========
2024-01-27T21:05:36 [INFO] Opening main db
2024-01-27T21:05:36 [ERROR] crates/zed/src/zed.rs:538: EOF while parsing a value at line 1 column 0
2024-01-27T21:05:36 [INFO] Opening main db
2024-01-27T21:05:36 [INFO] build git repository ".git"
2024-01-27T21:05:36 [INFO] set environment variables from shell:/bin/zsh, path:/Users/nlh/.pyenv/plugins/pyenv-virtualenv/shims:/Users/nlh/google-cloud-sdk/bin:/Users/nlh/.volta/bin:/Users/nlh/.docker/bin:/Users/nlh/.pyenv/shims:/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/Little Snitch.app/Contents/Components
2024-01-27T21:05:36 [INFO] set status on client 0: Authenticating
2024-01-27T21:05:36 [INFO] Opening main db
2024-01-27T21:05:36 [INFO] set status on client 90051: Connecting
2024-01-27T21:05:36 [INFO] Initializing default prettier with plugins {"prettier-plugin-tailwindcss", "prettier-plugin-svelte"}
2024-01-27T21:05:36 [INFO] starting language server "svelte-language-server", path: "/Users/nlh/Projects/cointrader-v2", id: 1
2024-01-27T21:05:36 [INFO] starting language server "tailwindcss-language-server", path: "/Users/nlh/Projects/cointrader-v2", id: 2
2024-01-27T21:05:36 [INFO] Node runtime install_if_needed
2024-01-27T21:05:37 [INFO] Node runtime install_if_needed
2024-01-27T21:05:37 [INFO] connected to rpc endpoint https://collab.zed.dev/rpc
2024-01-27T21:05:37 [INFO] Node runtime install_if_needed
2024-01-27T21:05:37 [INFO] add connection to peer
2024-01-27T21:05:37 [INFO] waiting for server hello
2024-01-27T21:05:37 [INFO] got server hello
2024-01-27T21:05:37 [INFO] set status to connected (connection id: ConnectionId { owner_id: 0, id: 0 }, peer id: PeerId { owner_id: 278, id: 470743 })
2024-01-27T21:05:37 [INFO] set status on client 90051: Connected { peer_id: PeerId { owner_id: 278, id: 470743 }, connection_id: ConnectionId { owner_id: 0, id: 0 } }
2024-01-27T21:05:37 [INFO] Node runtime install_if_needed
2024-01-27T21:05:37 [INFO] 0 unhandled notification LogMessage:
{
  "level": 0,
  "message": "[DEBUG] [agent] [2024-01-27T21:05:37.923Z] Agent service starting",
  "metadataStr": "[DEBUG] [agent] [2024-01-27T21:05:37.923Z]",
  "extra": [
    "Agent service starting"
  ]
}
2024-01-27T21:05:37 [INFO] 0 unhandled notification client/registerCapability:
{
  "registrations": [
    {
      "id": "6dffe145-56db-4c8b-89e8-6b665e63ea86",
      "method": "workspace/didChangeWorkspaceFolders",
      "registerOptions": {}
    }
  ]
}
2024-01-27T21:05:38 [INFO] Node runtime install_if_needed
2024-01-27T21:05:38 [INFO] 0 unhandled notification LogMessage:
{
  "level": 0,
  "message": "[DEBUG] [agent] [2024-01-27T21:05:38.307Z] Telemetry initialized",
  "metadataStr": "[DEBUG] [agent] [2024-01-27T21:05:38.307Z]",
  "extra": [
    "Telemetry initialized"
  ]
}
2024-01-27T21:07:00 [ERROR] crates/lsp/src/lsp.rs:255: invalid LSP message header ""
@noahlh noahlh added admin read Pending admin review bug [core label] triage Maintainer needs to classify the issue labels Jan 27, 2024
@michaelessiet
Copy link

Had this same issue last year. I haven't run into it as of late though, I'm not sure what changed

@noahlh
Copy link
Author

noahlh commented Jan 28, 2024

Happy to provide any other telemetry I can to help debug this. It's not impacting my system at all other than spinning a few extra cycles.

@JosephTLyons JosephTLyons added performance Feedback for performance issues, speed, memory usage, etc and removed triage Maintainer needs to classify the issue admin read Pending admin review labels Jan 28, 2024
@mrnugget
Copy link
Member

@noahlh I'm assuming you're opening Node.js/JavaScript projects, yes? If so, do you see the same 99% idle when you open a different project?

@noahlh
Copy link
Author

noahlh commented Jan 29, 2024

@mrnugget Great suggestion - thanks.

  1. I just opened Zed again and tried a C project. Normal CPU (woo hoo!)
  2. I then re-opened the previous project (which included JavaScript and Svelte files, among other types) but did NOT have any JS/Svelte files open (only config files). Normal CPU.
  3. I then opened a .svelte file (and tried the exact same sequence again with a .js file) and CPU immediately shot up to 400% then settled down to 100%. This persisted even after I closed the .svelte or .js files.

So that's something I think...?

@mrnugget
Copy link
Member

Okay, interesting! That makes me think the language server might be the cause here. Do the LSP logs show anything? If you open the command palette (cmd+shift+p) there's a debug: open language server logs action.

Is it only with .svelte files but not with .js files?

@noahlh
Copy link
Author

noahlh commented Jan 30, 2024

@mrnugget

The high CPU issue is happening with both .svelte and .js files.

First, opening a single .js file:

All LSP logs empty except for tailwindcss-language-server, which appears to be printing thousands of lines of simply:

stderr:

Screenshot 2024-01-30 at 10 21 37 AM

Next, restarting Zed and opening a single .svelte file:

svelte-language-server shows the following:

stderr: No svelte.config.js found. Using https://github.com/sveltejs/svelte-preprocess as fallback
stderr: Initialize new ts service at
stderr: Trying to load configs for /Users/nlh/Projects/my-project
stderr: RangeError: Set maximum size exceeded
stderr: at Set.add (<anonymous>)
stderr: at SyncReader._pushToQueue (/Users/nlh/Library/Application Support/Zed/languages/svelte-language-server/node_modules/@nodelib/fs.walk/out/readers/sync.js:19:21)
stderr: at SyncReader._handleEntry (/Users/nlh/Library/Application Support/Zed/languages/svelte-language-server/node_modules/@nodelib/fs.walk/out/readers/sync.js:52:18)
stderr: at SyncReader._handleDirectory (/Users/nlh/Library/Application Support/Zed/languages/svelte-language-server/node_modules/@nodelib/fs.walk/out/readers/sync.js:30:22)
stderr: at SyncReader._handleQueue (/Users/nlh/Library/Application Support/Zed/languages/svelte-language-server/node_modules/@nodelib/fs.walk/out/readers/sync.js:23:18)
stderr: at SyncReader.read (/Users/nlh/Library/Application Support/Zed/languages/svelte-language-server/node_modules/@nodelib/fs.walk/out/readers/sync.js:15:14)
stderr: at SyncProvider.read (/Users/nlh/Library/Application Support/Zed/languages/svelte-language-server/node_modules/@nodelib/fs.walk/out/providers/sync.js:11:29)
stderr: at ReaderSync.walkSync [as _walkSync] (/Users/nlh/Library/Application Support/Zed/languages/svelte-language-server/node_modules/@nodelib/fs.walk/out/index.js:20:21)
stderr: at ReaderSync.dynamic (/Users/nlh/Library/Application Support/Zed/languages/svelte-language-server/node_modules/fast-glob/out/readers/sync.js:13:21)
stderr: at ProviderSync.api (/Users/nlh/Library/Application Support/Zed/languages/svelte-language-server/node_modules/fast-glob/out/providers/sync.js:18:33)
stderr: SnapshotManager File Statistics:
stderr: Project files: 0
stderr: Svelte files: 1
stderr: From node_modules: 0
stderr: Total: 1

And tailwindcss-language-server has the same output as with a .js file -- thousands of lines of stderr:.

Hope this is helpful! Let me know if I can provide any further telemetry.

@mrnugget
Copy link
Member

Thanks! Okay, culprit found, I'd say. Seems like svelte-language-server and tailwindcss-language-server don't want to boot up in your project.

I just created a new Svelte project (default stuff, from here: https://kit.svelte.dev/docs/creating-a-project) and it works on my machine. So now the question is: why doesn't it work on yours?

I suspect it has something to do with the Tailwind language server, since that also start for JS files, but the svelte LS only for Svelte files.

We log every time we start a language server via node. The logs are in here:

~/Library/Application Support/Zed/node/node-v18.15.0-darwin-arm64/cache/_logs/

Does anything in these logs stand out? (You can delete them, then reproduce the issue to get new logs without having to look through them all)

Also: the project you're opening -- is that public? Can I run it? If not, do you have any specific configuration for tailwind or for the tailwind language server in your project?

@mrnugget
Copy link
Member

Oh, and another hail mary thing: do you have any Node files in your home directory? Like ~/node_modules, ~/package.json? Because that seems to be the cause for some language server issues: #4628 (comment)

@noahlh
Copy link
Author

noahlh commented Feb 1, 2024

@mrnugget I wish I had better (eg bad) news to report but those logs all look boring and clear. I'll attach the tailwind, typescript, and svelte logs here.

Alas the project is not public :( But I am happy to continue to experiment and be a guinea pig to solve this.

Here's all the dotfiles I have in ~/. let me know if any of these might be problematic and I can move things around if needed:

-r--------    1 nlh   staff       7 May 19  2023 .CFUserTextEncoding
-rw-r--r--@   1 nlh   staff   28676 Jan 31 17:44 .DS_Store
drwx------+  29 nlh   staff     928 Jan 31 18:02 .Trash
drwxr-xr-x@   4 nlh   staff     128 Jun 15  2023 .cache
drwx------    9 nlh   staff     288 Jan 25 08:30 .config
drwx------    3 nlh   staff      96 May 20  2023 .cups
drwxr-xr-x@   6 nlh   staff     192 Dec 18 15:26 .cursor
drwxr-xr-x@   5 nlh   staff     160 Aug 25 22:33 .cursor-tutor
drwxr-xr-x@  16 nlh   staff     512 Jan 14 19:51 .docker
drwxr-xr-x@  22 nlh   staff     704 Dec 28 11:23 .exploratory
-rw-r--r--@   1 nlh   staff     774 Dec 28 20:35 .exploratory_startup.log
-rw-r--r--    1 nlh   staff      54 May 21  2023 .gitconfig
-rw-------    1 nlh   staff      73 Jan  4 12:25 .lesshst
drwxr-xr-x    3 nlh   staff      96 May 19  2023 .local
-rw-------@   1 nlh   staff     188 May 20  2023 .netrc
-rw-------@   1 nlh   staff      21 May 21  2023 .node_repl_history
drwxr-xr-x@   5 nlh   staff     160 May 27  2023 .npm
drwxr-xr-x@   3 nlh   staff      96 Oct 23 19:53 .pnpm-state
-rw-r--r--@   1 nlh   staff      70 May 21  2023 .profile
drwxr-xr-x@   5 nlh   staff     160 Jun 15  2023 .proxyman
drwxr-xr-x@   3 nlh   staff      96 Jun 26  2023 .proxyman-data
drwxr-xr-x@   7 nlh   staff     224 Nov 14 18:09 .pyenv
-rw-------    1 nlh   staff       0 Nov 17 07:45 .python_history
-rw-------@   1 nlh   staff      39 Jul 26  2023 .rediscli_history
drwxr-xr-x   10 nlh   staff     320 Jan  6 08:08 .ssh
-rw-------    1 nlh   staff   28625 Jan 19 11:48 .viminfo
drwxr-xr-x@   9 nlh   staff     288 May 21  2023 .volta
drwxr-xr-x    4 nlh   staff     128 Nov 10  2021 .vscode
drwxr-xr-x@   6 nlh   staff     192 May 19  2023 .vscode-insiders
drwxr-xr-x@   5 nlh   staff     160 Jan 15 08:35 .warp
drwxr-xr-x@   3 nlh   staff      96 Jul 26  2023 .yarn
-rw-r--r--@   1 nlh   staff   49259 May 21  2023 .zcompdump
-rw-r--r--@   1 nlh   staff     166 May 21  2023 .zprofile
-rw-------    1 nlh   staff   60308 Jan 31 18:05 .zsh_history
drwx------    9 nlh   staff     288 Jan  7 11:23 .zsh_sessions
-rw-r--r--@   1 nlh   staff     756 Nov 14 18:09 .zshrc
-rw-r--r--@   1 nlh   staff     227 May 23  2023 .zshrc.backup

2024-02-01T02_02_18_885Z-debug-0.log
2024-02-01T02_02_19_102Z-debug-0.log
2024-02-01T02_02_19_999Z-debug-0.log

@mrnugget
Copy link
Member

mrnugget commented Feb 1, 2024

Thanks! My current working hypothesis: we're doing something wrong when parsing log output from LSPs and somehow end up in an infinite loop, which causes the CPU usage.

In order to confirm this at least somewhat, it would be great if we could disable the tailwind language server for you. Alas, we don't have a setting for that. So there's two options, as far as I can tell:

  1. You build & run Zed from source, but comment out this line here:
    Arc::new(tailwind::TailwindLspAdapter::new(node_runtime.clone())),
  2. We patch the installation of the tailwind-language-server Zed did for you to not do anything. I tried this, but it also doesn't work, because we then redownload the language server.

So I think for now we're stuck with (1). What do you think?

@noahlh
Copy link
Author

noahlh commented Feb 1, 2024

@mrnugget Happy to try (1)! Any excuse to put my CPU cycles to good use instead of browsing random internet sites is always a bonus for me :) I shall report back once I've done this....

@noahlh
Copy link
Author

noahlh commented Feb 1, 2024

@mrnugget Ok first results -- I commented out only line 264 (tailwind tree-parser for Svelte), recompiled, opened my project, and opened a single .svelte file and we're still at 100%+ CPU:

Screenshot 2024-02-01 at 8 40 35 AM

So that doesn't appear to be it. Any other ideas?

BTW - I compiled using cargo run (debug mode) so if there are any additional logs you want me to check, happy to do so and report back.

@mrnugget
Copy link
Member

mrnugget commented Feb 1, 2024

Okay, I have a possible fix in here: #7229 I'm going to merge this in a minute, then you can try running on main (with tailwind commented in).

You can also comment out both language servers, just so we can see that that's not the cause.

@noahlh
Copy link
Author

noahlh commented Feb 1, 2024

@mrnugget Ok confirmed the language server(s) are the issue -- I tried commenting out both lines and all good (no CPU troubles). I also tried just commenting out the Svelte language server (and not tailwind) and issue remains. So that's a good step in the right direction.

Now to figure out WHY my poor little project is making the language servers so unhappy. Is there additional loggage I can check to dive in further and see why they're choking?

@mrnugget
Copy link
Member

mrnugget commented Feb 1, 2024

Ah! Great to hear. So I think #7229 might then fix the CPU issue, but it will not fix the "language servers don't start" problem.

I also tried just commenting out the Svelte language server (and not tailwind) and issue remains. So that's a good step in the right direction.

So you're saying that only when BOTH start up things fail?

Is there additional loggage I can check to dive in further and see why they're choking?

I would assume that above the thousand lines of stderr: that tailwind at some point logged something?

Other than that: most language servers have specific env vars to increase/decrease log levels. rust-analyzer, for example, takes a RA_LOG env var.

@noahlh
Copy link
Author

noahlh commented Feb 1, 2024

So you're saying that only when BOTH start up things fail?

Sorry sorry I was unclear - no I meant that if either start up, CPU usage skyrockets. Only when both lines are commented out does it run smoothly.

@noahlh
Copy link
Author

noahlh commented Feb 1, 2024

I would assume that above the thousand lines of stderr: that tailwind at some point logged something?

I was hoping that would be the case, but I was unable to find anything other than the stderrs. Not sure if the log file truncates at some point.

Other than that: most language servers have specific env vars to increase/decrease log levels. rust-analyzer, for example, takes a RA_LOG env var.

Ok I will explore this -- I'll see if I can get something out of the Svelte language server since I'm a bit more familiar with that ecosystem. More to come....

@noahlh
Copy link
Author

noahlh commented Feb 2, 2024

@mrnugget Small update - on my local build, I did manage to get some interesting (?) output from the tailwind language server logs:

stderr:
stderr: <--- Last few GCs --->
stderr:
stderr: [23922:0x130040000]    83129 ms: Mark-sweep 4008.0 (4130.3) -> 3996.6 (4132.3) MB, 2591.5 / 0.0 ms  (average mu = 0.129, current mu = 0.006) task; scavenge might not succeed
stderr: [23922:0x130040000]    85741 ms: Mark-sweep 4010.0 (4132.3) -> 3998.6 (4134.3) MB, 2593.8 / 0.0 ms  (average mu = 0.071, current mu = 0.007) task; scavenge might not succeed
stderr:
stderr:
stderr: <--- JS stacktrace --->
stderr:
stderr: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
stderr: 1: 0x1026d149c node::Abort() [/Users/nlh/Library/Application Support/Zed/node/node-v18.15.0-darwin-arm64/bin/node]
stderr: 2: 0x1026d168c node::ModifyCodeGenerationFromStrings(v8::Local<v8::Context>, v8::Local<v8::Value>, bool) [/Users/nlh/Library/Application Support/Zed/node/node-v18.15.0-darwin-arm64/bin/node]
stderr: 3: 0x10282a26c v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/Users/nlh/Library/Application Support/Zed/node/node-v18.15.0-darwin-arm64/bin/node]
stderr: 4: 0x1029d51f8 v8::internal::EmbedderStackStateScope::EmbedderStackStateScope(v8::internal::Heap*, v8::internal::EmbedderStackStateScope::Origin, cppgc::EmbedderStackState) [/Users/nlh/Library/Application Support/Zed/node/node-v18.15.0-darwin-arm64/bin/node]
stderr: 5: 0x1029d8e00 v8::internal::Heap::CollectSharedGarbage(v8::internal::GarbageCollectionReason) [/Users/nlh/Library/Application Support/Zed/node/node-v18.15.0-darwin-arm64/bin/node]
stderr: 6: 0x1029d5df4 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::internal::GarbageCollectionReason, char const*, v8::GCCallbackFlags) [/Users/nlh/Library/Application Support/Zed/node/node-v18.15.0-darwin-arm64/bin/node]
stderr: 7: 0x1029d324c v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/Users/nlh/Library/Application Support/Zed/node/node-v18.15.0-darwin-arm64/bin/node]
stderr: 8: 0x102a54eb0 v8::internal::ScavengeJob::Task::RunInternal() [/Users/nlh/Library/Application Support/Zed/node/node-v18.15.0-darwin-arm64/bin/node]
stderr: 9: 0x10272f434 node::PerIsolatePlatformData::RunForegroundTask(std::__1::unique_ptr<v8::Task, std::__1::default_delete<v8::Task>>) [/Users/nlh/Library/Application Support/Zed/node/node-v18.15.0-darwin-arm64/bin/node]
stderr: 10: 0x10272e0a0 node::PerIsolatePlatformData::FlushForegroundTasksInternal() [/Users/nlh/Library/Application Support/Zed/node/node-v18.15.0-darwin-arm64/bin/node]
stderr: 11: 0x102ff394c uv__async_io [/Users/nlh/Library/Application Support/Zed/node/node-v18.15.0-darwin-arm64/bin/node]
stderr: 12: 0x1030060f0 uv__io_poll [/Users/nlh/Library/Application Support/Zed/node/node-v18.15.0-darwin-arm64/bin/node]
stderr: 13: 0x102ff3e1c uv_run [/Users/nlh/Library/Application Support/Zed/node/node-v18.15.0-darwin-arm64/bin/node]
stderr: 14: 0x102621704 node::SpinEventLoop(node::Environment*) [/Users/nlh/Library/Application Support/Zed/node/node-v18.15.0-darwin-arm64/bin/node]
stderr: 15: 0x10270e3f8 node::NodeMainInstance::Run() [/Users/nlh/Library/Application Support/Zed/node/node-v18.15.0-darwin-arm64/bin/node]
stderr: 16: 0x10269e430 node::LoadSnapshotDataAndRun(node::SnapshotData const**, node::InitializationResult const*) [/Users/nlh/Library/Application Support/Zed/node/node-v18.15.0-darwin-arm64/bin/node]
stderr: 17: 0x10269e6b4 node::Start(int, char**) [/Users/nlh/Library/Application Support/Zed/node/node-v18.15.0-darwin-arm64/bin/node]
stderr: 18: 0x189a990e0 start [/usr/lib/dyld]
stderr:
stderr:
stderr:
stderr:
stderr:
stderr:
stderr:
stderr:
stderr:
...ad infinitum

@mrnugget
Copy link
Member

mrnugget commented Feb 2, 2024

Is your project really big by any chance? I do know that for some projects one needs to increase the memory limits of Node from the standard 512mb: https://gist.github.com/motss/f55b92ccab0d434fa6e6cfd07423014b

I'm pretty sure #7229 will then fix the CPU issue, because it fixes the infinite stderr lines. Alas, it doesn't fix the node process running out of memory.

@noahlh
Copy link
Author

noahlh commented Feb 2, 2024

Is your project really big by any chance?

@mrnugget I don't think so -- it's a few thousand lines of code and a few dozen .svelte components. It is definitely a non-traditional project though -- I'm using a Crystal (language) backend with a node + Svelte rendering layer for SSR and Svelte in the front-end. So it doesn't fit into the traditional mold of a Svelte project (maybe directory structure is different?), but it's also not different in a crazy way either.

I'm trying to see if I can get more debug output out of the svelte-language-server or Tailwind language server. Since the issue is happening with both, I'm leaning toward this being a general node issue (vs. something specific to Svelte).

Any hints on where/how I can enable more verbose node output?

@mpfaff
Copy link

mpfaff commented Feb 12, 2024

@mrnugget

The high CPU issue is happening with both .svelte and .js files.

First, opening a single .js file:

All LSP logs empty except for tailwindcss-language-server, which appears to be printing thousands of lines of simply:

stderr:
Screenshot 2024-01-30 at 10 21 37 AM

Next, restarting Zed and opening a single .svelte file:

svelte-language-server shows the following:

stderr: No svelte.config.js found. Using https://github.com/sveltejs/svelte-preprocess as fallback
stderr: Initialize new ts service at
stderr: Trying to load configs for /Users/nlh/Projects/my-project
stderr: RangeError: Set maximum size exceeded
stderr: at Set.add (<anonymous>)
stderr: at SyncReader._pushToQueue (/Users/nlh/Library/Application Support/Zed/languages/svelte-language-server/node_modules/@nodelib/fs.walk/out/readers/sync.js:19:21)
stderr: at SyncReader._handleEntry (/Users/nlh/Library/Application Support/Zed/languages/svelte-language-server/node_modules/@nodelib/fs.walk/out/readers/sync.js:52:18)
stderr: at SyncReader._handleDirectory (/Users/nlh/Library/Application Support/Zed/languages/svelte-language-server/node_modules/@nodelib/fs.walk/out/readers/sync.js:30:22)
stderr: at SyncReader._handleQueue (/Users/nlh/Library/Application Support/Zed/languages/svelte-language-server/node_modules/@nodelib/fs.walk/out/readers/sync.js:23:18)
stderr: at SyncReader.read (/Users/nlh/Library/Application Support/Zed/languages/svelte-language-server/node_modules/@nodelib/fs.walk/out/readers/sync.js:15:14)
stderr: at SyncProvider.read (/Users/nlh/Library/Application Support/Zed/languages/svelte-language-server/node_modules/@nodelib/fs.walk/out/providers/sync.js:11:29)
stderr: at ReaderSync.walkSync [as _walkSync] (/Users/nlh/Library/Application Support/Zed/languages/svelte-language-server/node_modules/@nodelib/fs.walk/out/index.js:20:21)
stderr: at ReaderSync.dynamic (/Users/nlh/Library/Application Support/Zed/languages/svelte-language-server/node_modules/fast-glob/out/readers/sync.js:13:21)
stderr: at ProviderSync.api (/Users/nlh/Library/Application Support/Zed/languages/svelte-language-server/node_modules/fast-glob/out/providers/sync.js:18:33)
stderr: SnapshotManager File Statistics:
stderr: Project files: 0
stderr: Svelte files: 1
stderr: From node_modules: 0
stderr: Total: 1

And tailwindcss-language-server has the same output as with a .js file -- thousands of lines of stderr:.

Hope this is helpful! Let me know if I can provide any further telemetry.

I'm seeing the same thing (100% CPU usage and thousands of lines of stderr:) with the Zig language server

@mrnugget
Copy link
Member

@mpfaff what version of Zed are you on? Can you reproduce this with a sample Zig project?

@mrnugget
Copy link
Member

@noahlh sorry for dropping the ball on this! So I think what I'd try is to modify the Tailwind/Svelte language servers to run Node with some arguments. For example, here's how the node command is constructed for Tailwind:

Ok(LanguageServerBinary {
path: self.node.binary_path().await?,
arguments: server_binary_arguments(&server_path),
})
}

And here's Svelte:

Ok(LanguageServerBinary {
path: self.node.binary_path().await?,
arguments: server_binary_arguments(&server_path),
})
}

I'd change the code there to add the --max-old-space-size argument from here: https://gist.github.com/motss/f55b92ccab0d434fa6e6cfd07423014b

Then see if something crashes or not.

@mpfaff
Copy link

mpfaff commented Feb 14, 2024

@mrnugget

what version of Zed are you on?

Zed 0.121.7

Can you reproduce this with a sample Zig project?

I've not tried. It seems to happen only while I'm editing code, and not constantly. I would imagine it's some specific change to the file that is causing the problem, but I have no idea where to begin with testing for that.

@mrnugget
Copy link
Member

mrnugget commented Jul 4, 2024

High load still persists for at least 10 minutes after running the project in my case. Run project several times to make it eat even more CPU.

I cannot reproduce this. I opened the project, I ran cargo run in the built-in terminal, waited for the command to create the 350mb file. See:

screenshot-2024-07-04-13.58.10.mp4

Even if I then open the file: I only a spike of CPU usage and then it drops back down.

@alekspetrov
Copy link

image

It looks like it has issues with JS/TS projects, is Zed indexing node_modules?

@alekspetrov
Copy link

alekspetrov commented Jul 5, 2024

I found the solution for JS projects.

Add exclusion for /node_modules and it helps!

Lines added to the settings.json:

"file_scan_exclusions": {
    "node_modules": true
  },

%CPU usage decreased to 1:
image

@mrnugget
Copy link
Member

mrnugget commented Jul 5, 2024

It doesn't index node_modules if they're .gitignored. Is it possible that they're not?

@alekspetrov
Copy link

Absolutely /node_modules was in .gitignore while IDLE was 100%. Only forcing with settings helps to avoid deps indexing.

@Ilia-TheNetworkFirm
Copy link

I have the same issue
Excluding the node_modules dir via settings didn't help

Zed 0.142.6

Screenshot 2024-07-08 at 18 13 52 Screenshot 2024-07-08 at 18 14 25

@mrnugget
Copy link
Member

mrnugget commented Jul 8, 2024

Can someone reproduce this problem with language servers turned off?

{
  "enable_language_server": false,
}

@alekspetrov
Copy link

Can someone reproduce this problem with language servers turned off?

{
  "enable_language_server": false,
}

I have significant drop in %CPU usage. It was like 10-15, now 0.5.

@mrnugget
Copy link
Member

mrnugget commented Jul 9, 2024

Yeah. One possible explanation for high CPU usage is that the language servers can send Zed a ton of messages, which can get CPU usage up. Example: if I restart rust-analyzer in the zed repo, then obviously rust-analyzer will eat 300% CPU, but Zed's CPU usage also goes up from <1% to ~40% as long as rust-analyzer is blasting it indexing codebase... messages.

@cocovs
Copy link

cocovs commented Jul 18, 2024

same issue : After opening the golang project, the CPU is very high

version : Zed 0.144.3 (linux)

weMh3JJqX5

@mrnugget
Copy link
Member

@cocovs is that gopls maybe?

@cocovs
Copy link

cocovs commented Jul 24, 2024

@cocovs is that gopls maybe?可能是 gopls 吗?

yes,CPU useage drops back down after language servers turned off

@ruanfdev
Copy link

Oh, and another hail mary thing: do you have any Node files in your home directory? Like ~/node_modules, ~/package.json? Because that seems to be the cause for some language server issues: #4628 (comment)

@mrnugget - Using Zed 0.148.0 on Ubuntu 24.04, i tried this solution, for a moment it looked like it worked then went back to running high cpu % after about 5-10min of running (but not as high as before, only at about 25-55%, not 95-100% anymore) on the node process. Also running with '"enable_language_server": false' drastically dropped the cpu usage to below 1%. I took a screenshot of my culprate (while cpu usage ran high), hope it helps:
Screenshot from 2024-08-15 08-11-31

@mrnugget
Copy link
Member

Seems to be the tailwindcss-language-server, right? Does that mean it happens when you open a specific file?

@ruanfdev
Copy link

No it happens even on idle (i haven't work with tailwindcss in months, only php recently for converting Natural Programs to PHP). So i am not sure how to pinpoint an issue that shouldn't exist.

@mrnugget
Copy link
Member

Does it go away when you disable language servers, like I proposed above?

{
  "enable_language_server": false,
}

@ruanfdev
Copy link

See my initial comment above with the screenshot (#6894 (comment)). It drastically drops the CPU usage, meaning that it runs buttery smooth.

@mrnugget
Copy link
Member

Argh! Sorry about that, I mixed up usernames. The project that's causing this issue is not open-source by any chance?

@ruanfdev
Copy link

ruanfdev commented Aug 22, 2024

No stress :). Not at all, it is completely in-house with no tailwind usage at all. Files we use are as follows and very basic (PHP, CSS, JS & HTML). I am also up to version 0.149.3, trying every day and every update to see if it gets better but no change.

@ruanfdev
Copy link

@mrnugget - I would really like to start using Zed full-time, replacing VScode but with the CPU usage issue i just can't. Please let me know what i can do to help resolve this issue.

@mrnugget
Copy link
Member

What I need are steps to reproduce the issue reliably. Right now I can't do much because it seems like the facts are "sometimes with some language servers CPU goes up to 100%", but that's too wide for me to dig in.

@ruanfdev
Copy link

@mrnugget I completely understand. Is there any possibility that i can only disable the tailwind language server node similarly to:
{ "enable_language_server": false, }

If so, please advise on how to do it.
Because in my case it is about 4-10min (i tested twice now to get the exact timing) after starting up Zed every single time & every single time it is the tailwind language server node.

@mrnugget
Copy link
Member

Yeah, you can disable only Tailwind. See here: https://zed.dev/docs/configuring-languages#choosing-language-servers

For example:

{
  "languages": {
    "PHP": {
      "language_servers": ["intelephense", "!phpactor", "!tailwindcss-language-server", "..."]
    }
  }
}

That disabled phpactor and tailwindcss-language-server for PHP.

@ruanfdev
Copy link

ruanfdev commented Sep 2, 2024

@mrnugget
Just an update after a lot of testing over the weekend, it could be something i used in my "settings.json" but this i am not sure about what it could be. I think i resolved my issue: 1) closed Zed -> 2) went into ~/.config and deleted the zed folder -> 3) relaunched Zed and waited (after about 3-4 minutes the CPU usage jumped up but after about 1-2min it came back down to normal and stayed there for the remainder of my coding session).

Herewith my old settings.json:
{ "assistant": { "default_model": { "provider": "copilot_chat", "model": "gpt-4o" }, "version": "2" }, "base_keymap": "VSCode", "ui_font_size": 15, "buffer_font_size": 15, "theme": { "mode": "system", "light": "One Light", "dark": "One Dark" }, "preferred_line_length": 800, "autosave": "on_focus_change", "tab_bar": { "show_nav_history_buttons": false }, "tabs": { "git_status": true }, "prettier": { "singleQuote": false }, "languages": { "PHP": { "language_servers": [ "phpactor", "!intelephense", "!tailwindcss-language-server", "..." ] }, "CSS": { "language_servers": [ "!tailwindcss-language-server", "..." ] } } }

@mrnugget
Copy link
Member

mrnugget commented Sep 4, 2024

I don't see anything suspicious in there.

So did disabling tailwindcss-language-server not help at all?

@ruanfdev
Copy link

ruanfdev commented Sep 4, 2024

That was my problem as well, i didn't see anything strange. But no, disabling tailwindcss-language-server still caused it to use high cpu usage around the same timing (after about 4-10min after starting Zed), the only thing that completely fixed it at the time was "enable_language_server": false but i needed that for other languages.

But as stated in the previous message, that solution also fixed my problem although it still jumps very high for about 1min every time i start up Zed then settles down:

  1. closed Zed -> 2) went into ~/.config and deleted the zed folder -> 3) relaunched Zed and waited (after about 3-4 minutes the CPU usage jumped up but after about 1-2min it came back down to normal and stayed there for the remainder of my coding session)

@mrnugget
Copy link
Member

mrnugget commented Sep 4, 2024

But no, disabling tailwindcss-language-server still caused it to use high cpu usage around the same timing (after about 4-10min after starting Zed), the only thing that completely fixed it at the time was "enable_language_server": false but i needed that for other languages.

So that means it could be another language server then, yes? When you disable tailwind, and wait until this happens, which language servers do you have running? (Open debug: open language server logs) to get a list

@ruanfdev
Copy link

ruanfdev commented Sep 5, 2024

  1. Yes it can be another language server, it's just weird that the tailwind node still runs high when it happens even though i disabled it on php and css for testing.
  2. As of this morning running Zed 0.151.1, with no languages disabled and only minor changes to settings.json like "preferred_line_length": 800, "prettier": {"singleQuote": false},, the only spike i got was around 2min after startup for about 30 seconds, then stable throughout
  3. I opened debug: open language server logs when the spike happened for what it's worth and got the following from:
    • vscode-css-language-server:

    Error while validating file:///dir/dir2/dir3/css/standard.css: Cannot read properties of null (reading 'validProperties')
    TypeError: Cannot read properties of null (reading 'validProperties')
    at LintConfigurationSettings.getSetting (/home/user/.local/share/zed/languages/vscode-css-language-server/node_modules/vscode-css-languageservice/lib/umd/services/lintRules.js:78:29)
    at new LintVisitor (/home/user/.local/share/zed/languages/vscode-css-language-server/node_modules/vscode-css-languageservice/lib/umd/services/lint.js:53:41)
    at LintVisitor.entries (/home/user/.local/share/zed/languages/vscode-css-language-server/node_modules/vscode-css-languageservice/lib/umd/services/lint.js:41:29)
    at CSSValidation.doValidation (/home/user/.local/share/zed/languages/vscode-css-language-server/node_modules/vscode-css-languageservice/lib/umd/services/cssValidation.js:34:60)
    at _callee15$ (/home/user/.local/share/zed/languages/vscode-css-language-server/node_modules/vscode-langservers-extracted/lib/css-language-server/cssServer.js:288:83)
    at tryCatch (/home/user/.local/share/zed/languages/vscode-css-language-server/node_modules/regenerator-runtime/runtime.js:64:40)
    at Generator.invoke (/home/user/.local/share/zed/languages/vscode-css-language-server/node_modules/regenerator-runtime/runtime.js:299:22)
    at Generator.next (/home/user/.local/share/zed/languages/vscode-css-language-server/node_modules/regenerator-runtime/runtime.js:124:21)
    at asyncGeneratorStep (/home/user/.local/share/zed/languages/vscode-css-language-server/node_modules/vscode-langservers-extracted/lib/css-language-server/cssServer.js:53:103)
    at _next (/home/user/.local/share/zed/languages/vscode-css-language-server/node_modules/vscode-langservers-extracted/lib/css-language-server/cssServer.js:55:194)

    • tailwindcss-language-server (last line on quote below going on/duplicated for about 800 lines):

    Setting up server…
    Listening for messages…
    Language mappings are currently set via initialization options (userLanguages). This is deprecated and will be removed in a future release. Please use the tailwindCSS.includeLanguages setting instead.
    Searching for Tailwind CSS projects in the workspace's folders.
    {"tailwind":{"version":"3.4.4","features":["layer:base","separator:root","content-list","jit","css-at-config","relative-content-paths","transpiled-configs"],"isDefaultVersion":true}}

@mrnugget
Copy link
Member

mrnugget commented Sep 5, 2024

2. As of this morning running Zed 0.151.1, with no languages disabled and only minor changes to settings.json [...] then stable throughout

That's good, right? Or am I missing something?

@ruanfdev
Copy link

ruanfdev commented Sep 5, 2024

No you are correct, everything looks great. I just don't understand why, but i'm happy. Thanks a lot for your assistance throughout, i'll update again if i run into any issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug [core label] performance Feedback for performance issues, speed, memory usage, etc
Projects
None yet
Development

No branches or pull requests