zed icon indicating copy to clipboard operation
zed copied to clipboard

High CPU (100%+)

Open noahlh opened this issue 1 year ago • 53 comments
trafficstars

Check for existing issues

  • [X] 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 avatar Jan 27 '24 21:01 noahlh

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

michaelessiet avatar Jan 27 '24 23:01 michaelessiet

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.

noahlh avatar Jan 28 '24 04:01 noahlh

@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?

mrnugget avatar Jan 29 '24 15:01 mrnugget

@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...?

noahlh avatar Jan 29 '24 20:01 noahlh

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?

mrnugget avatar Jan 30 '24 17:01 mrnugget

@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.

noahlh avatar Jan 30 '24 18:01 noahlh

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 avatar Jan 31 '24 14:01 mrnugget

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: https://github.com/zed-industries/zed/issues/4628#issuecomment-1917263859

mrnugget avatar Jan 31 '24 14:01 mrnugget

@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

noahlh avatar Feb 01 '24 02:02 noahlh

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: https://github.com/zed-industries/zed/blob/a745e9b58b0cc809725eaa1dd4611478e47aa19d/crates/zed/src/languages.rs#L264
  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?

mrnugget avatar Feb 01 '24 16:02 mrnugget

@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 avatar Feb 01 '24 16:02 noahlh

@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.

noahlh avatar Feb 01 '24 16:02 noahlh

Okay, I have a possible fix in here: https://github.com/zed-industries/zed/pull/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.

mrnugget avatar Feb 01 '24 16:02 mrnugget

@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?

noahlh avatar Feb 01 '24 17:02 noahlh

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.

mrnugget avatar Feb 01 '24 17:02 mrnugget

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 avatar Feb 01 '24 17:02 noahlh

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 avatar Feb 01 '24 17:02 noahlh

@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

noahlh avatar Feb 02 '24 02:02 noahlh

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 https://github.com/zed-industries/zed/pull/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.

mrnugget avatar Feb 02 '24 07:02 mrnugget

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?

noahlh avatar Feb 02 '24 16:02 noahlh

@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

mpfaff avatar Feb 12 '24 23:02 mpfaff

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

mrnugget avatar Feb 13 '24 08:02 mrnugget

@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:

https://github.com/zed-industries/zed/blob/0fb6b32bc341d7f1f7d859965f9ef90d76c5cab9/crates/zed/src/languages/tailwind.rs#L74-L78

And here's Svelte:

https://github.com/zed-industries/zed/blob/0fb6b32bc341d7f1f7d859965f9ef90d76c5cab9/crates/zed/src/languages/svelte.rs#L72-L76

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.

mrnugget avatar Feb 13 '24 08:02 mrnugget

@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.

mpfaff avatar Feb 14 '24 14:02 mpfaff

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.

Would be great to have a reproducible example. As in: "if I have a file like this, cursor here, type Foo, ..."

mrnugget avatar Feb 14 '24 16:02 mrnugget

I'll see what I can do. If I stumble across anything reproducible I'll make sure to leave an update here.

mpfaff avatar Feb 15 '24 04:02 mpfaff

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.

Would be great to have a reproducible example. As in: "if I have a file like this, cursor here, type Foo, ..."

Not a reproducible example, but I caught it quick enough to get you a stack trace from ZLS this time!

stderr: thread 17339466 panic: reached unreachable code
stderr: ???:?:?: 0x10ed1432c in _debug.assert (???)
stderr: ???:?:?: 0x10ee99e02 in _ast.nodesAtLoc (???)
stderr: ???:?:?: 0x10ee4a06e in _features.inlay_hints.writeRangeInlayHint (???)
stderr: ???:?:?: 0x10edf4796 in _Server.inlayHintHandler (???)
stderr: ???:?:?: 0x10edb4855 in _Server.sendRequestSync__anon_21269 (???)
stderr: ???:?:?: 0x10ed79ba1 in _Server.processMessage (???)
stderr: ???:?:?: 0x10ed3d9d9 in _Server.processMessageReportError (???)
stderr: ???:?:?: 0x10ed23fa1 in _Server.processJob (???)
stderr: ???:?:?: 0x10ed2303e in _Thread.Pool.spawn__anon_12957.Closure.runFn (???)
stderr: ???:?:?: 0x10eda51ec in _Thread.Pool.worker (???)
stderr: ???:?:?: 0x10ed6952a in _Thread.callFn__anon_19085 (???)
stderr: ???:?:?: 0x10ed31b82 in _Thread.PosixThreadImpl.spawn__anon_15847.Instance.entryFn (???)
stderr: ???:?:?: 0x7ff811152258 in ??? (libsystem_pthread.dylib)
stderr: Unwind error at address `libsystem_pthread.dylib:0x7ff811152258` (error.InvalidDebugInfo), trace may be incomplete
stderr:
stderr: ???:?:?: 0x7ff81114dc7a in ??? (libsystem_pthread.dylib)
stderr: ???:?:?: 0x0 in ??? (???)

mpfaff avatar Feb 15 '24 15:02 mpfaff

I've got a specific case in a large project where simply moving the cursor with the mouse in a particular file triggers the aforementioned error consistently.

mpfaff avatar Feb 15 '24 15:02 mpfaff

This might also be of interest:

stderr: error: (store ): Failed to execute build runner to collect build configuration, command:
stderr: ~/.tools/zig/0.12/zig build --build-runner ~/Library/Caches/zls/build_runner.zig
stderr: Error: ~/Library/Caches/zls/build_runner.zig:28:9: error: local variable is never mutated
stderr: ~/Library/Caches/zls/build_runner.zig:28:9: note: consider using 'const'
stderr:
stderr: error: (store ): Failed to load build configuration for file:///path/to/project/build.zig (error: error.RunFailed)

I think I might be using a newer version of Zig than is supported by the version of ZLS used by Zed. I'm not sure if that is a Zed issue or if ZLS just has not released an update yet.

mpfaff avatar Feb 15 '24 15:02 mpfaff

@mpfaff thanks! Yeah, I think ZLS/Zig version mismatch can be the cause.

But besides the crash -- are you seeing high CPU usage or no? Because if it's only about ZLS not working for Zig, then I think we should create a separate ticket for that.

mrnugget avatar Feb 16 '24 08:02 mrnugget