zed icon indicating copy to clipboard operation
zed copied to clipboard

Zed uses lot of RAM

Open tanaybhomia opened this issue 1 year ago • 32 comments

Check for existing issues

  • [X] Completed

Describe the bug / provide steps to reproduce it

Here zed is using around 2GB of ram and I have checked it on Reddit some people were saying their device is showing just 200mb to 300mb of ram usage with these kinds of project.

Environment

OS - Fedora 40 Workstation Hardware Model - ASUSTeK COMPUTER INC. VivoBook Processor - AMD Ryzen™ 7 5800HS Memory - 16GB Gnome - 46 Linux Kernel - Linux 6.10.11-200.fc40.x86_64

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

Screenshot from 2024-10-02 18-23-03 Screenshot from 2024-10-02 18-24-09

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

Zed.log

2024-10-02T17:16:13.182467034+05:30 [INFO] ========== starting zed ========== 2024-10-02T17:16:13.332487855+05:30 [INFO] perform; 2024-10-02T17:16:13.332602972+05:30 [INFO] authenticate; 2024-10-02T17:16:13.332737114+05:30 [INFO] read_command; 2024-10-02T17:16:13.333205995+05:30 [INFO] new; 2024-10-02T17:16:13.333310091+05:30 [INFO] socket reader; 2024-10-02T17:16:13.333438412+05:30 [INFO] Opening main db 2024-10-02T17:16:13.333845798+05:30 [INFO] keep_updated; 2024-10-02T17:16:13.334505408+05:30 [INFO] Opening main db 2024-10-02T17:16:13.338805931+05:30 [INFO] Using git binary path: None 2024-10-02T17:16:13.364648978+05:30 [ERROR] theme not found: Adwaita Pastel Dark 2024-10-02T17:16:13.364837091+05:30 [ERROR] No such file or directory (os error 2) about ["/home/tanay/.config/github-copilot"] 2024-10-02T17:16:13.365633488+05:30 [INFO] initializing context server client 2024-10-02T17:16:13.365775405+05:30 [INFO] Registering built-in prompt template: content_prompt 2024-10-02T17:16:13.366111517+05:30 [INFO] Registering built-in prompt template: edit_workflow 2024-10-02T17:16:13.366391834+05:30 [INFO] Registering built-in prompt template: step_resolution 2024-10-02T17:16:13.366824808+05:30 [INFO] Registering built-in prompt template: terminal_assistant_prompt 2024-10-02T17:16:13.367069498+05:30 [INFO] No prompt template overrides directory found at /home/tanay/.local/share/zed/prompt_overrides. Using built-in prompts. 2024-10-02T17:16:13.367447498+05:30 [INFO] extensions updated. loading 2, reloading 0, unloading 0 2024-10-02T17:16:13.369345546+05:30 [WARN] request completed with error: failed to connect to the server 2024-10-02T17:16:13.369452918+05:30 [WARN] request completed with error: failed to connect to the server 2024-10-02T17:16:13.369539611+05:30 [WARN] request completed with error: failed to connect to the server 2024-10-02T17:16:13.369625011+05:30 [WARN] request completed with error: failed to connect to the server 2024-10-02T17:16:13.369784972+05:30 [WARN] request completed with error: failed to connect to the server 2024-10-02T17:16:13.370766667+05:30 [INFO] activate is not implemented on Linux, ignoring the call 2024-10-02T17:16:13.37190141+05:30 [INFO] perform; 2024-10-02T17:16:13.372019051+05:30 [INFO] authenticate; 2024-10-02T17:16:13.372134468+05:30 [INFO] read_command; 2024-10-02T17:16:13.372243213+05:30 [WARN] request completed with error: failed to connect to the server 2024-10-02T17:16:13.372371604+05:30 [WARN] request completed with error: failed to connect to the server 2024-10-02T17:16:13.372482823+05:30 [WARN] request completed with error: failed to connect to the server 2024-10-02T17:16:13.372670366+05:30 [WARN] request completed with error: failed to connect to the server 2024-10-02T17:16:13.372787426+05:30 [INFO] socket reader; 2024-10-02T17:16:13.377726239+05:30 [INFO] Opening main db 2024-10-02T17:16:13.377847617+05:30 [WARN] request completed with error: failed to connect to the server 2024-10-02T17:16:13.379215418+05:30 [INFO] new; 2024-10-02T17:16:13.379323902+05:30 [WARN] request completed with error: failed to connect to the server 2024-10-02T17:16:13.380027575+05:30 [INFO] keep_updated; 2024-10-02T17:16:13.446684128+05:30 [INFO] Enabling Vulkan Portability 2024-10-02T17:16:13.446789796+05:30 [INFO] Enabling color space support 2024-10-02T17:16:13.464347479+05:30 [INFO] Adapter: "AMD Radeon Graphics (RADV RENOIR)" 2024-10-02T17:16:13.464490488+05:30 [INFO] No ray tracing extensions are supported 2024-10-02T17:16:13.479418468+05:30 [INFO] Using surface present mode MAILBOX 2024-10-02T17:16:13.4798559+05:30 [WARN] Unable to forbid exclusive full screen 2024-10-02T17:16:13.480583718+05:30 [INFO] Creating a descriptor pool for at most 16 sets 2024-10-02T17:16:13.480694626+05:30 [INFO] Creating a descriptor pool for at most 16 sets 2024-10-02T17:16:13.480795326+05:30 [INFO] Initializing Blade pipelines for surface SurfaceInfo { format: Bgra8UnormSrgb, alpha: PreMultiplied } 2024-10-02T17:16:13.486594526+05:30 [INFO] Using GPU: GPUSpecs { is_software_emulated: false, device_name: "AMD Radeon Graphics (RADV RENOIR)", driver_name: "radv", driver_info: "Mesa 24.1.7" } 2024-10-02T17:16:13.488754787+05:30 [INFO] set status on client 0: Authenticating 2024-10-02T17:16:13.48911801+05:30 [INFO] perform; 2024-10-02T17:16:13.489230551+05:30 [INFO] authenticate; 2024-10-02T17:16:13.489356538+05:30 [INFO] read_command; 2024-10-02T17:16:13.489753484+05:30 [INFO] socket reader; 2024-10-02T17:16:13.49138443+05:30 [WARN] request completed with error: failed to connect to the server 2024-10-02T17:16:13.491486622+05:30 [INFO] Opening main db 2024-10-02T17:16:13.492577953+05:30 [WARN] request completed with error: failed to connect to the server 2024-10-02T17:16:13.493054389+05:30 [INFO] Opening main db 2024-10-02T17:16:13.494243203+05:30 [INFO] new; 2024-10-02T17:16:13.495109482+05:30 [INFO] keep_updated; 2024-10-02T17:16:13.512184497+05:30 [INFO] set status on client 235766: Connecting 2024-10-02T17:16:13.513154951+05:30 [WARN] request completed with error: failed to connect to the server 2024-10-02T17:16:13.516915159+05:30 [WARN] request completed with error: failed to connect to the server 2024-10-02T17:16:13.517252483+05:30 [ERROR] No worktree for path: "/usr/share/gnome-shell/extensions/[email protected]/dark.css" 2024-10-02T17:16:13.536107725+05:30 [INFO] attempting to start language server "tailwindcss-language-server", path: "/home/tanay/Dev/Repos/FlowDoro", id: 1 2024-10-02T17:16:13.536274208+05:30 [INFO] Initializing default prettier with plugins {} 2024-10-02T17:16:13.536505222+05:30 [INFO] Initializing default prettier with plugins {} 2024-10-02T17:16:13.538876249+05:30 [INFO] Initializing default prettier with plugins {} 2024-10-02T17:16:13.539359938+05:30 [INFO] fetching latest version of language server "tailwindcss-language-server" 2024-10-02T17:16:13.53947767+05:30 [INFO] Node runtime install_if_needed 2024-10-02T17:16:13.543439897+05:30 [WARN] request completed with error: failed to connect to the server 2024-10-02T17:16:13.543571144+05:30 [WARN] request completed with error: failed to connect to the server 2024-10-02T17:16:13.582768352+05:30 [INFO] Using surface present mode MAILBOX 2024-10-02T17:16:13.585694743+05:30 [WARN] Unable to forbid exclusive full screen 2024-10-02T17:16:13.605076214+05:30 [INFO] set environment variables from shell:/bin/zsh, path:/home/tanay/bin:/home/tanay/.local/bin:/usr/local/bin:/home/tanay/bin:/home/tanay/.local/bin:/usr/local/bin:/home/tanay/.cargo/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin 2024-10-02T17:16:13.632024909+05:30 [INFO] attempting to start language server "vtsls", path: "/home/tanay/Dev/Repos/FlowDoro", id: 2 2024-10-02T17:16:13.632195679+05:30 [INFO] attempting to start language server "eslint", path: "/home/tanay/Dev/Repos/FlowDoro", id: 3 2024-10-02T17:16:13.632354528+05:30 [INFO] Initializing default prettier with plugins {} 2024-10-02T17:16:13.634824571+05:30 [INFO] fetching latest version of language server "vtsls" 2024-10-02T17:16:13.63498891+05:30 [INFO] fetching latest version of language server "eslint" 2024-10-02T17:16:13.635104467+05:30 [INFO] downloading language server "eslint" 2024-10-02T17:16:13.635415622+05:30 [INFO] Initializing default prettier with plugins {} 2024-10-02T17:16:13.636583798+05:30 [WARN] request completed with error: failed to connect to the server 2024-10-02T17:16:13.677186528+05:30 [INFO] Node runtime install_if_needed 2024-10-02T17:16:13.711740779+05:30 [INFO] Initializing default prettier with plugins {} 2024-10-02T17:16:13.711863139+05:30 [INFO] attempting to start language server "vscode-html-language-server", path: "/home/tanay/Dev/Repos/FlowDoro", id: 4 2024-10-02T17:16:13.712655698+05:30 [WARN] request completed with error: failed to connect to the server 2024-10-02T17:16:13.776308325+05:30 [INFO] Node runtime install_if_needed 2024-10-02T17:16:13.831519534+05:30 [INFO] connected to rpc endpoint https://collab.zed.dev/rpc 2024-10-02T17:16:13.865197708+05:30 [INFO] starting language server process. binary path: "/home/tanay/.local/share/zed/node/node-v22.5.1-linux-x64/bin/node", working directory: "/", args: ["/home/tanay/.local/share/zed/copilot/copilot-v0.5.0/dist/agent.js", "--stdio"] 2024-10-02T17:16:13.865448861+05:30 [INFO] Node runtime install_if_needed 2024-10-02T17:16:13.957995418+05:30 [INFO] Node runtime install_if_needed 2024-10-02T17:16:14.053920166+05:30 [INFO] Node runtime install_if_needed 2024-10-02T17:16:14.143742773+05:30 [INFO] using project environment for language server "eslint", id: 3 2024-10-02T17:16:14.143900259+05:30 [INFO] Node runtime install_if_needed 2024-10-02T17:16:14.144025635+05:30 [INFO] starting language server process. binary path: "/home/tanay/.local/share/zed/node/node-v22.5.1-linux-x64/bin/node", working directory: "/home/tanay/Dev/Repos/FlowDoro", args: ["--max-old-space-size=8192", "/home/tanay/.local/share/zed/languages/eslint/vscode-eslint-release/2.4.4/vscode-eslint/server/out/eslintServer.js", "--stdio"] 2024-10-02T17:16:14.220753739+05:30 [INFO] Language server with id 0 sent unhandled notification LogMessage: { "level": 0, "message": "[DEBUG] [agent] [2024-10-02T11:46:14.216Z] Agent service starting", "metadataStr": "[DEBUG] [agent] [2024-10-02T11:46:14.216Z]", "extra": [ "Agent service starting" ] }

tanaybhomia avatar Oct 03 '24 01:10 tanaybhomia

Quite recently, Zed took up over 2GB of RAM in my case. Despite everything, it is still software in a very development stage - anyway, such situations should not occur when it advertises itself as a very light editor.

widersky avatar Oct 10 '24 05:10 widersky

Yeah I agree, Will see if this gets fixed in the recent updates, I hope they are working on this.

tanaybhomia avatar Oct 10 '24 05:10 tanaybhomia

Hey @tanaybhomia, we have a handful of other issues about high RAM usage; do any of these cover what you are experiencing here? I'd like to consolidate the issues, if so:

  • https://github.com/zed-industries/zed/issues/7361
  • https://github.com/zed-industries/zed/issues/7939
  • https://github.com/zed-industries/zed/issues/10389
  • https://github.com/zed-industries/zed/issues/13552
  • https://github.com/zed-industries/zed/issues/14833
  • https://github.com/zed-industries/zed/issues/15692

JosephTLyons avatar Oct 12 '24 19:10 JosephTLyons

I think the last issue listed no #15692, this is the closest to me.

tanaybhomia avatar Oct 13 '24 13:10 tanaybhomia

Why is Zed spawning so many instances of rust-analyzer?

image

edfloreshz avatar Oct 22 '24 19:10 edfloreshz

Why is Zed spawning so many instances of rust-analyzer?

image

I've also noticed something similar whenever Zed is using a lot of RAM, it always has multiple instances of every active LSP server running. It seems like Zed is starting up new instances of the LSPs without shutting down old ones for some reason?

Reapimus avatar Oct 23 '24 02:10 Reapimus

image Zed will occasionally freeze and consume upwards of 9GB of ram, no idea what the cause is.

dy-tea avatar Nov 04 '24 22:11 dy-tea

9GB ??? How large is the project that you are running ?

tanaybhomia avatar Nov 04 '24 23:11 tanaybhomia

9GB ??? How large is the project that you are running ? image

dy-tea avatar Nov 05 '24 13:11 dy-tea

Have you checked that if it is spawning Rust analyzers like this comment says

tanaybhomia avatar Nov 05 '24 13:11 tanaybhomia

not sure why, not too many files opened but zed started to consume up to several hundreds of gigabytes, and it's quite reproduceable

Screenshot 2024-12-17 at 9 58 43 PM

emakarov avatar Dec 17 '24 13:12 emakarov

Why is Zed spawning so many instances of rust-analyzer?

Have you checked that if it is spawning Rust analyzers like https://github.com/zed-industries/zed/issues/18673#issuecomment-2430108163 comment says

This is something I wish to know, too. I believe it is related to how many crates a workspace has:

  • I have 26 Cargo.toml files (1 is the workspace root, 2 are not part of the workspace, 23 are listed as workspace members)
  • Zed has spawned 27 rust-analyzer processes
  • The result is that Zed + child processes currently use 20 GB of memory.

In case it helps, here is my lsp configuration:

"lsp": {
    "rust-analyzer": {
      "initialization_options": {
        "cargo": {
          "features": "all"
        },
        "procMacro": {
          "enable": true
        },
        "diagnostics": {
          "disabled": ["non_snake_case"]
        },
        "checkOnSave": true
      }
    }
  }

Potentially relevant: #20767

@edfloreshz how many rust-analyzer processes do you have and how many Cargo.toml files are in your folder? @maan2003 Since you seem to have the same issue: Same question to you

DragonDev1906 avatar Dec 17 '24 17:12 DragonDev1906

I think it was fixed by https://github.com/zed-industries/zed/pull/21787

cc @ConradIrwin

maan2003 avatar Dec 17 '24 17:12 maan2003

I have a single Cargo.toml with 7 rust-analyzer processes open at the moment.

edfloreshz avatar Dec 17 '24 17:12 edfloreshz

it is due to multi buffers, if you restore a multi buffer it will start rust analyzer every time

maan2003 avatar Dec 17 '24 17:12 maan2003

I think is relate #21906

CharlesChen0823 avatar Dec 19 '24 06:12 CharlesChen0823

This issue is getting serious it seems. I open log files ranging from 50mb-200mb. And ZED consumes 19GB of memory for some reason on my 16gb MBP. Also if you keep it open it increases constantly.

And another major issue is when I click to close the file. Entire Zed becomes unresponsive in Mac with that colorful circle kept on spinning. And I have to kill Zed to close it.

I tried to do this in vscode and the ram usage wasn't too much. But This Ram issue is getting out of hand now. Every update I'm waiting for this issue to be listed in the changelog. 😞 .

Hope the team takes this as priority as well.

Ayanrocks avatar Jan 07 '25 17:01 Ayanrocks

This issue is getting serious it seems. I open log files ranging from 50mb-200mb. And ZED consumes 19GB of memory for some reason on my 16gb MBP. Also if you keep it open it increases constantly.

And another major issue is when I click to close the file. Entire Zed becomes unresponsive in Mac with that colorful circle kept on spinning. And I have to kill Zed to close it.

I tried to do this in vscode and the ram usage wasn't too much. But This Ram issue is getting out of hand now. Every update I'm waiting for this issue to be listed in the changelog. 😞 .

Hope the team takes this as priority as well.

Since A picture is worth a thousand words, Here are some screenshots for proof. Only One instance of Zed is running and I've closed the log files that I've opened. Still it's consuming 5.5GB of memory for some reason.

Screenshot 2025-01-08 at 10 57 32 PM Screenshot 2025-01-08 at 10 57 29 PM

Ayanrocks avatar Jan 08 '25 17:01 Ayanrocks

I found a repro for this

https://github.com/zed-industries/zed/issues/20767#issuecomment-2613574099

maan2003 avatar Jan 24 '25 23:01 maan2003

not sure why, not too many files opened but zed started to consume up to several hundreds of gigabytes, and it's quite reproduceable Screenshot 2024-12-17 at 9 58 43 PM

What are you using that has so much RAM to give to processes?

playbahn avatar Mar 06 '25 18:03 playbahn

Its on Macbook Air. I think it is including swap

emakarov avatar Mar 07 '25 04:03 emakarov

Temporary switched to other editors hoping to see RAM issue fixed in future version changelogs

emakarov avatar Mar 07 '25 04:03 emakarov

Image When doing basic gpt stuff. Macbook Pro 14in with 8GB RAM...

I saw that Zed is using an older version of cosmic-text on Linux (version = "0.11.2"). It should be updated to the latest version (0.13.2), which contains a lot of memory usage optimizations.

I also didn't see any malloc tunables being used, so I'd highly recommend setting a static M_MMAP_THRESHOLD on Linux to a reasonable value on application startup. libcosmic has malloc functions declared here which get called early on application startup like so.

If you don't set a static MMAP_THRESHOLD, then GNU libc malloc will dynamically increase its mmap threshold—the threshold where malloc chooses between using in-process brk arenas for smaller allocations, and OS-allocated mmaps for large allocations. This can result in a lot of memory fragmentation that will never be trimmed and freed back to the OS.

GNU libc malloc also does not automatically trim its brk arenas, so it can be necessary to malloc call malloc::trim(0) after an expensive operation has freed up a lot of memory. If desiring to use mimalloc on Linux, it also has similar trim functions.

mmstick avatar Mar 24 '25 00:03 mmstick

As of today, zed seems to spawn rust-analyzer instances (in a loop maybe?) until it runs out of RAM (I have 64 GiB) and Ubuntu crashes.

This is for compiling a hello world Bevy project (I exit before it runs out of RAM in this case):

https://github.com/user-attachments/assets/ac94edc4-4128-40b4-9f75-81894b129706

mcobzarenco avatar Apr 06 '25 18:04 mcobzarenco

~~I am experiencing the same problem here. Zed's node server consumption increases to 2-3GB for a small project.~~

Image

Environment

  • Macbook Pro M3, 16GB
  • OS version: Sequoia 15.3.1

EDIT: Was on mistake on my end. Python code analysis was configured to analyze all files within a workspace and not only opened files.

V-Legendre avatar Apr 22 '25 16:04 V-Legendre

24GB of RAM when Zed was on background for an hour with a little C project opened.

a0405u avatar May 19 '25 20:05 a0405u

Just received the following notification:

Image

edfloreshz avatar May 20 '25 15:05 edfloreshz

Seems I find something related to use a lot of RAM (may be already mentioned by someone)

  1. [0 s] Start htop to see memory usage before start zed, we see 3.5G RAM are used
  2. [0-15 s] Start zed and run python script for generate two json files. First one with indents, second one without. RAM usage up a bit on generation and return to normal value 3.8G in the end
  3. [15-23 s] Open json file indent.json (40 Mb), it opens instantly but RAM usage jumps to 5.0G
  4. [23-50 s] Now lets switch between script and this json file - we will see that RAM usage are increased at every opening indent.json. Now RAM usage 7G
  5. [50+ s] Lets open json file with no indents noindent.json (also 40Mb). And zed freeze for more than 2 minutes and takes 8G RAM (from 7G to 15G)

https://github.com/user-attachments/assets/65e1b293-5346-4a1f-acd8-13ae196e85bb

skilletfun avatar May 28 '25 18:05 skilletfun

I am facing the same issue too

onlypfachi avatar May 29 '25 09:05 onlypfachi