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
50.29k stars 3.1k forks source link

Zed freezes with high memory usage when using inline assist to rewrite entire files #18062

Closed EDLLT closed 1 week ago

EDLLT commented 2 months ago

Check for existing issues

Describe the bug / provide steps to reproduce it

Related: https://github.com/zed-industries/zed/issues/15692 https://github.com/zed-industries/zed/issues/17937

Zed Version: 0.152.4 Architecture: x86_64 OS: Ubuntu 24.04

When I use inline assist on my file with 19k tokens, zed starts eating up all my ram and swap then my whole system crashes shortly afterwards.

Screenshot from 2024-09-19 13-27-45

File I was performing inline assist on(in hopes of improving reproducability) https://github.com/flxzt/rnote/blob/main/crates/rnote-engine/src/pens/typewriter/penevents.rs I was telling Zed AI in the inline assist feature after selecting the whole script to "remove occurrences of audio usage"

Environment

            .-/+oossssoo+/-.               edllt@HP 
        `:+ssssssssssssssssss+:`           -------- 
      -+ssssssssssssssssssyyssss+-         OS: Ubuntu 24.04.1 LTS x86_64 
\   .ossssssssssssssssssdMMMNysssso.        Kernel: 6.8.0-41-generic 
   /ssssssssssshdmmNNmmyNMMMMhssssss/      Uptime: 10 days, 2 hours, 10 mins 
  +ssssssssshmydMMMMMMMNddddyssssssss+     Packages: 3971 (dpkg), 49 (flatpak), 
 /sssssssshNMMMyhhyyyyhmNMMMNhssssssss/    Shell: bash 5.2.21 
.ssssssssdMMMNhsssssssssshNMMMdssssssss.   Resolution: 1366x768, 2560x1440 
+sssshhhyNMMNyssssssssssssyNMMMysssssss+   DE: GNOME 46.0 
ossyNMMMNyMMhsssssssssssssshmmmhssssssso   WM: Mutter 
ossyNMMMNyMMhsssssssssssssshmmmhssssssso   WM Theme: Adwaita 
+sssshhhyNMMNyssssssssssssyNMMMysssssss+   Theme: Yaru-dark [GTK2/3] 
.ssssssssdMMMNhsssssssssshNMMMdssssssss.   Icons: Yaru [GTK2/3] 
 /sssssssshNMMMyhhyyyyhdNMMMNhssssssss/    Terminal: gnome-terminal 
  +sssssssssdmydMMMMMMMMddddyssssssss+     CPU: AMD Ryzen 7 3700X (16) @ 3.600G 
   /ssssssssssshdmNNNNmyNMMMMhssssss/      GPU: NVIDIA GeForce RTX 3060 Ti Lite 
    .ossssssssssssssssssdMMMNysssso.       Memory: 3845MiB / 15895MiB 
      -+sssssssssssssssssyyyssss+-
        `:+ssssssssssssssssss+:`                                   
            .-/+oossssoo+/-.                                       

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

Zed.log


Zed.log

Captured the log while it was running the inline assist

CharlesChen0823 commented 2 months ago

I can give an step to reproduce.

justageek commented 1 month ago

I'm using 0.154.4 and it still goes bonkers as soon as launched and consumes all RAM, Macbook pro Intel chip

mikayla-maki commented 2 weeks ago

Did some profiling with @mgsloan in heaptrack, it looks like the streaming diff pushes a lot memory, specifically around StreamingDiff::push_new.

mgsloan commented 1 week ago

Here's a screenshot of heaptrack flamegraph for this case.

Image

mgsloan commented 1 week ago

Confirmed that this is fixed in #20296 , good stuff @as-cii !!! Memory profiler flamegraph is a lot more normal and no big leak

image