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
49.26k stars 2.98k forks source link

GPUI window resizes are very slow on Linux #15311

Open 143mailliw opened 3 months ago

143mailliw commented 3 months ago

Check for existing issues

Describe the bug / provide steps to reproduce it

When Zed (or seemingly any GPUI based app) is opened and resized on Linux, the actual window resize operation takes multiple seconds, and freezes the entire application while this is occurring.

This issue is substantially worse after I pulled GPUI today.

Environment

Zed: v0.145.1 (Zed) OS: Linux Wayland arch unknown Memory: 31 GiB Architecture: x86_64

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

As requested in the Zed Discord, attached is a flamegraph of my application (https://github.com/143mailliw/muzak) exhibiting this issue. Most of the time is spent in various calls to the AMD Vulkan driver from blade_graphics. It's in a ZIP file to avoid github sanitizing the SVG.

flamegraph.zip

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

No response

mikayla-maki commented 3 months ago

flamegraph 2

mikayla-maki commented 3 months ago

It looks like most of the time here is spent in the blade resize, thoughts on what the issue could be there @kvark?

143mailliw commented 3 months ago

No one seems to be able to reproduce this on any Nvidia cards or Intel iGPUs yet. Might be a problem with RADV (the libvulkan_radeon.so in the flamegraph) specifically.

VitorRamos commented 3 months ago

I can reproduce this on nvida card (wayland only). On x11 this is not an issue.

Running gpui example resize_way

Env: OS: Linux Wayland ubuntu 22.04 Memory: 31.2 GB Architecture: x86_64 GPU: NVIDIA GeForce RTX 2070 with Max-Q Design || NVIDIA || 550.90.07

GlacierFox commented 3 months ago

Got this issue also.

Wayland.

NVIDIA 960.

Driver Version : 550.78

roverflow commented 2 months ago

I have slightly different issue, mine crashes

[2024-08-12T01:10:54+05:30 ERROR fs] No such file or directory (os error 2) about ["/home/roverflow/.config/github-copilot"]
xkbcommon: ERROR: /usr/share/X11/locale/en_US.UTF-8/Compose:1661:1: unrecognized keysym "dead_hamza" on left-hand side
xkbcommon: ERROR: /usr/share/X11/locale/en_US.UTF-8/Compose:1662:1: unrecognized keysym "dead_hamza" on left-hand side
xkbcommon: ERROR: /usr/share/X11/locale/en_US.UTF-8/Compose:1663:1: unrecognized keysym "dead_hamza" on left-hand side
xkbcommon: ERROR: /usr/share/X11/locale/en_US.UTF-8/Compose:1664:1: unrecognized keysym "dead_hamza" on left-hand side
xkbcommon: ERROR: /usr/share/X11/locale/en_US.UTF-8/Compose:1665:1: unrecognized keysym "dead_hamza" on left-hand side
[2024-08-12T01:10:55+05:30 ERROR assistant] no worktrees when constructing ProjectLspAdapterDelegate
[2024-08-12T01:11:09+05:30 ERROR zed::reliability] {
  "thread": "main",
  "payload": "GPU has crashed, and no debug information is available.",
  "location_data": {
    "file": "/home/actions-runner/.cargo/git/checkouts/blade-ea462a0faa3f9995/7e497c5/blade-graphics/src/vulkan/command.rs",
    "line": 439
  },
  "backtrace": [
    "core::panicking::panic_fmt",
    "<blade_graphics::hal::Context as blade_graphics::traits::CommandDevice>::submit",
    "gpui::platform::blade::blade_renderer::BladeRenderer::draw",
    "<gpui::platform::linux::wayland::window::WaylandWindow as gpui::platform::PlatformWindow>::draw",
    "gpui::window::Window::new::{{closure}}::{{closure}}",
    "gpui::window::Window::new::{{closure}}",
    "gpui::platform::linux::wayland::window::WaylandWindowStatePtr::frame",
    "<gpui::platform::linux::wayland::client::WaylandClientStatePtr as wayland_client::event_queue::Dispatch<wayland_client::protocol::wl_callback::WlCallback,wayland_backend::sys::client::ObjectId>>::event",
    "wayland_client::event_queue::queue_callback",
    "<core::cell::RefCell<calloop::sources::DispatcherInner<S,F>> as calloop::sources::EventDispatcher<Data>>::process_events",
    "<gpui::platform::linux::wayland::client::WaylandClient as gpui::platform::linux::platform::LinuxClient>::run",
    "gpui::platform::linux::platform::<impl gpui::platform::Platform for P>::run",
    "gpui::app::App::run",
    "zed::main",
    "std::sys_common::backtrace::__rust_begin_short_backtrace",
    "std::rt::lang_start::{{closure}}",
    "std::rt::lang_start_internal",
    "main",
    "__libc_start_call_main",
    "__libc_start_main_alias_1",
    "_start"
  ],
  "app_version": "0.147.2",
  "release_channel": "Zed",
  "os_name": "Linux Wayland",
  "os_version": "nobara 40",
  "architecture": "x86_64",
  "panicked_on": 1723405269367,
  "installation_id": "61e28ec3-7de1-41b7-afa5-0677c1860a80",
  "session_id": "216e41f6-e33d-4d61-a9ef-a89b4a3021c9"
}
143mailliw commented 2 months ago

I have slightly different issue, mine crashes

[2024-08-12T01:10:54+05:30 ERROR fs] No such file or directory (os error 2) about ["/home/roverflow/.config/github-copilot"]
xkbcommon: ERROR: /usr/share/X11/locale/en_US.UTF-8/Compose:1661:1: unrecognized keysym "dead_hamza" on left-hand side
xkbcommon: ERROR: /usr/share/X11/locale/en_US.UTF-8/Compose:1662:1: unrecognized keysym "dead_hamza" on left-hand side
xkbcommon: ERROR: /usr/share/X11/locale/en_US.UTF-8/Compose:1663:1: unrecognized keysym "dead_hamza" on left-hand side
xkbcommon: ERROR: /usr/share/X11/locale/en_US.UTF-8/Compose:1664:1: unrecognized keysym "dead_hamza" on left-hand side
xkbcommon: ERROR: /usr/share/X11/locale/en_US.UTF-8/Compose:1665:1: unrecognized keysym "dead_hamza" on left-hand side
[2024-08-12T01:10:55+05:30 ERROR assistant] no worktrees when constructing ProjectLspAdapterDelegate
[2024-08-12T01:11:09+05:30 ERROR zed::reliability] {
  "thread": "main",
  "payload": "GPU has crashed, and no debug information is available.",
  "location_data": {
    "file": "/home/actions-runner/.cargo/git/checkouts/blade-ea462a0faa3f9995/7e497c5/blade-graphics/src/vulkan/command.rs",
    "line": 439
  },
  "backtrace": [
    "core::panicking::panic_fmt",
    "<blade_graphics::hal::Context as blade_graphics::traits::CommandDevice>::submit",
    "gpui::platform::blade::blade_renderer::BladeRenderer::draw",
    "<gpui::platform::linux::wayland::window::WaylandWindow as gpui::platform::PlatformWindow>::draw",
    "gpui::window::Window::new::{{closure}}::{{closure}}",
    "gpui::window::Window::new::{{closure}}",
    "gpui::platform::linux::wayland::window::WaylandWindowStatePtr::frame",
    "<gpui::platform::linux::wayland::client::WaylandClientStatePtr as wayland_client::event_queue::Dispatch<wayland_client::protocol::wl_callback::WlCallback,wayland_backend::sys::client::ObjectId>>::event",
    "wayland_client::event_queue::queue_callback",
    "<core::cell::RefCell<calloop::sources::DispatcherInner<S,F>> as calloop::sources::EventDispatcher<Data>>::process_events",
    "<gpui::platform::linux::wayland::client::WaylandClient as gpui::platform::linux::platform::LinuxClient>::run",
    "gpui::platform::linux::platform::<impl gpui::platform::Platform for P>::run",
    "gpui::app::App::run",
    "zed::main",
    "std::sys_common::backtrace::__rust_begin_short_backtrace",
    "std::rt::lang_start::{{closure}}",
    "std::rt::lang_start_internal",
    "main",
    "__libc_start_call_main",
    "__libc_start_main_alias_1",
    "_start"
  ],
  "app_version": "0.147.2",
  "release_channel": "Zed",
  "os_name": "Linux Wayland",
  "os_version": "nobara 40",
  "architecture": "x86_64",
  "panicked_on": 1723405269367,
  "installation_id": "61e28ec3-7de1-41b7-afa5-0677c1860a80",
  "session_id": "216e41f6-e33d-4d61-a9ef-a89b4a3021c9"
}

What is the output of vulkaninfo --summary?

roverflow commented 2 months ago

@143mailliw

==========
VULKANINFO
==========

Vulkan Instance Version: 1.3.280

Instance Extensions: count = 24
-------------------------------
VK_EXT_acquire_drm_display             : extension revision 1
VK_EXT_acquire_xlib_display            : extension revision 1
VK_EXT_debug_report                    : extension revision 10
VK_EXT_debug_utils                     : extension revision 2
VK_EXT_direct_mode_display             : extension revision 1
VK_EXT_display_surface_counter         : extension revision 1
VK_EXT_headless_surface                : extension revision 1
VK_EXT_surface_maintenance1            : extension revision 1
VK_EXT_swapchain_colorspace            : extension revision 4
VK_KHR_device_group_creation           : extension revision 1
VK_KHR_display                         : extension revision 23
VK_KHR_external_fence_capabilities     : extension revision 1
VK_KHR_external_memory_capabilities    : extension revision 1
VK_KHR_external_semaphore_capabilities : extension revision 1
VK_KHR_get_display_properties2         : extension revision 1
VK_KHR_get_physical_device_properties2 : extension revision 2
VK_KHR_get_surface_capabilities2       : extension revision 1
VK_KHR_portability_enumeration         : extension revision 1
VK_KHR_surface                         : extension revision 25
VK_KHR_surface_protected_capabilities  : extension revision 1
VK_KHR_wayland_surface                 : extension revision 6
VK_KHR_xcb_surface                     : extension revision 6
VK_KHR_xlib_surface                    : extension revision 6
VK_LUNARG_direct_driver_loading        : extension revision 1

Instance Layers: count = 12
---------------------------
VK_LAYER_FROG_gamescope_wsi_x86    Gamescope WSI (XWayland Bypass) Layer (x86)    1.3.221  version 1
VK_LAYER_FROG_gamescope_wsi_x86_64 Gamescope WSI (XWayland Bypass) Layer (x86_64) 1.3.221  version 1
VK_LAYER_MANGOAPP_overlay          Mangoapp Layer                                 1.3.0    version 1
VK_LAYER_MANGOAPP_overlay          Mangoapp Layer                                 1.3.0    version 1
VK_LAYER_MANGOHUD_overlay_x86      Vulkan Hud Overlay                             1.3.0    version 1
VK_LAYER_MANGOHUD_overlay_x86_64   Vulkan Hud Overlay                             1.3.0    version 1
VK_LAYER_MESA_device_select        Linux device selection layer                   1.3.211  version 1
VK_LAYER_MESA_overlay              Mesa Overlay layer                             1.3.211  version 1
VK_LAYER_NV_optimus                NVIDIA Optimus layer                           1.3.280  version 1
VK_LAYER_OBS_vkcapture_32          OBS Linux game capture                         1.3.280  version 1
VK_LAYER_OBS_vkcapture_64          OBS Linux game capture                         1.3.280  version 1
VK_LAYER_VKBASALT_post_processing  a post processing layer                        1.3.223  version 1

Devices:
========
GPU0:
    apiVersion         = 1.3.280
    driverVersion      = 560.31.2.0
    vendorID           = 0x10de
    deviceID           = 0x2482
    deviceType         = PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
    deviceName         = NVIDIA GeForce RTX 3070 Ti
    driverID           = DRIVER_ID_NVIDIA_PROPRIETARY
    driverName         = NVIDIA
    driverInfo         = 560.31.02
    conformanceVersion = 1.3.8.2
    deviceUUID         = 15fa9d54-cb18-4097-268a-97d1e329eb28
    driverUUID         = 2ea321e9-be53-5ad1-be3a-562d522ec1fb
GPU1:
    apiVersion         = 1.3.289
    driverVersion      = 24.2.99
    vendorID           = 0x1002
    deviceID           = 0x164e
    deviceType         = PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
    deviceName         = AMD Radeon Graphics (RADV RAPHAEL_MENDOCINO)
    driverID           = DRIVER_ID_MESA_RADV
    driverName         = radv
    driverInfo         = Mesa 24.3.0-devel
    conformanceVersion = 1.3.0.0
    deviceUUID         = 00000000-0e00-0000-0000-000000000000
    driverUUID         = 414d442d-4d45-5341-2d44-525600000000
GPU2:
    apiVersion         = 1.3.289
    driverVersion      = 0.0.1
    vendorID           = 0x10005
    deviceID           = 0x0000
    deviceType         = PHYSICAL_DEVICE_TYPE_CPU
    deviceName         = llvmpipe (LLVM 18.1.6, 256 bits)
    driverID           = DRIVER_ID_MESA_LLVMPIPE
    driverName         = llvmpipe
    driverInfo         = Mesa 24.3.0-devel (LLVM 18.1.6)
    conformanceVersion = 1.3.1.1
    deviceUUID         = 6d657361-3234-2e33-2e30-2d6465766500
    driverUUID         = 6c6c766d-7069-7065-5555-494400000000
Isholiday commented 2 months ago

I also got this issue on Wayland. Resizing takes 5 to 10 seconds. If i try to do something while resizing like clicking on zed it also stops responding. OS: Arch Linux x86_64 NVIDIA GeForce RTX 3060 Mobile Driver Version: 555.58.02

kvark commented 2 months ago

@roverflow that is interesting. Here are the things that would be great to try if you have time:

  1. build Zed in debug (from code) and run. This automatically enables GPU work validation.
  2. run examples from https://github.com/kvark/blade and see if they crash
digitalsignalperson commented 1 month ago

wanting to try zed but funny enough the first thing I do opening a window is to try and resize it...

I'm on arch linux with KDE plasma, and maybe complicated having three gpus (an amd card, an nvidia card, integrated)

ls -la /dev/dri/by-path/
total 0
drwxr-xr-x 2 root root 160 Sep  9 20:54 ./
drwxr-xr-x 3 root root 180 Sep  9 20:54 ../
lrwxrwxrwx 1 root root   8 Sep  9 20:54 pci-0000:00:02.0-card -> ../card1
lrwxrwxrwx 1 root root  13 Sep  9 20:54 pci-0000:00:02.0-render -> ../renderD129
lrwxrwxrwx 1 root root   8 Sep  9 20:54 pci-0000:01:00.0-card -> ../card0
lrwxrwxrwx 1 root root  13 Sep  9 20:54 pci-0000:01:00.0-render -> ../renderD128
lrwxrwxrwx 1 root root   8 Sep  9 20:54 pci-0000:04:00.0-card -> ../card2
lrwxrwxrwx 1 root root  13 Sep  9 20:54 pci-0000:04:00.0-render -> ../renderD130

Here's the output from running zed

zeditor --foreground
[2024-09-17T16:17:40-07:00 ERROR fs] No such file or directory (os error 2) about ["/home/me/.config/github-copilot"]
[2024-09-17T16:17:40-07:00 ERROR assistant] no worktrees when constructing ProjectLspAdapterDelegate
[2024-09-17T16:17:51-07:00 ERROR gpui] window not found
[2024-09-17T16:17:51-07:00 ERROR gpui] window not found

As a hack (which is the same method I discovered to solve my chromium gpu problems), I can run zed in a bubblewrap environment, exposing it to only one GPU.

bwrap \
    --symlink usr/bin /bin \
    --symlink usr/bin /sbin \
    --symlink usr/lib /lib \
    --symlink usr/lib64 /lib64 \
    --ro-bind /usr/bin /usr/bin \
    --ro-bind /usr/lib /usr/lib \
    --ro-bind /usr/lib64 /usr/lib64 \
    --ro-bind /usr/share /usr/share \
    --ro-bind /etc/resolv.conf /etc/resolv.conf \
    --ro-bind /etc/ssl /etc/ssl \
    --ro-bind /etc/ca-certificates /etc/ca-certificates \
    --ro-bind /etc/fonts /etc/fonts \
    --tmpfs /tmp \
    --proc /proc \
    --dev /dev \
    --dev-bind /dev/dri/renderD130 /dev/dri/renderD130 \
    --dev-bind /dev/dri/card2 /dev/dri/card2 \
    --ro-bind /sys/dev/char /sys/dev/char \
    --ro-bind /sys/devices /sys/devices \
    --dir "$XDG_RUNTIME_DIR" \
    --ro-bind /tmp/.X11-unix /tmp/.X11-unix \
    --ro-bind "$XDG_RUNTIME_DIR/wayland-0" "$XDG_RUNTIME_DIR/wayland-0" \
    --ro-bind "$XDG_RUNTIME_DIR/pipewire-0" "$XDG_RUNTIME_DIR/pipewire-0" \
    --ro-bind "$XDG_RUNTIME_DIR/pulse" "$XDG_RUNTIME_DIR/pulse" \
    --unshare-all \
    --share-net \
    --die-with-parent \
    --new-session \
    --dir $HOME \
    --chdir $HOME \
    -- zeditor --foreground

the output is

[2024-09-17T23:24:52+00:00 ERROR fs] No such file or directory (os error 2) about ["/home/me/.config/github-copilot"]
Authorization required, but no authorization protocol specified

Authorization required, but no authorization protocol specified

Authorization required, but no authorization protocol specified

Authorization required, but no authorization protocol specified

Authorization required, but no authorization protocol specified

Authorization required, but no authorization protocol specified

Authorization required, but no authorization protocol specified

Authorization required, but no authorization protocol specified

[2024-09-17T23:24:52+00:00 ERROR assistant] no worktrees when constructing ProjectLspAdapterDelegate
[2024-09-17T23:24:52+00:00 ERROR zed] Is a directory (os error 21)
[2024-09-17T23:24:59+00:00 ERROR gpui] window not found
[2024-09-17T23:24:59+00:00 ERROR gpui] window not found

still see that gpui] window not found, but resizing is 100x faster. But still kinda laggy.

kvark commented 1 month ago

@digitalsignalperson that's interesting, and weird. Having multiple physical devices that aren't used by the current context shouldn't affect the resize speed. Perhaps, you are just making it run on a different physical device when bubblewrapping?

digitalsignalperson commented 1 month ago

@kvark yes the bwrap example is preventing 2 of the gpu's from being seen by the program, forcing it to use one I pick and preventing any code paths that might get confused by multiple devices I guess.

Normally the simple solution is to set DRI_PRIME= to tell the app what gpu to use, but I find it is ignored by some applications.

To confirm if multiple GPUs is the culprit, others could provide details if they have both an integrated and discrete gpu enabled

GlacierFox commented 1 month ago

@kvark yes the bwrap example is preventing 2 of the gpu's from being seen by the program, forcing it to use one I pick and preventing any code paths that might get confused by multiple devices I guess.

Normally the simple solution is to set DRI_PRIME= to tell the app what gpu to use, but I find it is ignored by some applications.

To confirm if multiple GPUs is the culprit, others could provide details if they have both an integrated and discrete gpu enabled

I've got this problem an I'm using only a single GPU (Nvidia 980, RHEL, KDE)

I've also tried it on a different machine (Nvidia 1050, Fedora, KDE) to the same effect.

letterlock commented 1 month ago

Unsure if this helps, but I have a slightly unique situation so I'll throw my experience on the pile.

I recently (a few days ago) switched out my old NVIDIA RTX 3060 (driver version 555) for an AMD Radeon RX 6750 XT.

On the Nvidia card the slow resizes were very noticeable and quite extreme, sometimes taking multiple seconds to resolve and creating artifacts during.

However, on the AMD, the resizes are quite a bit faster. Still noticeably slower than other windows, but always resolving in under a second and without the same artifacts.

I'm using EndeavourOS with KDE Plasma under wayland.

ssynaptics commented 2 weeks ago

Able to reproduce. I'm using Arch Linux, NVIDIA 560.35 drivers KDE Plasma 6.2.0 and a RTX 3070 as the GPU. Had this problem for atleast 1.5-2 months.

kvark commented 1 week ago

@ssynaptics would you be able to grab a sampling profile trace from this scenario, when running on Zed that has debug symbols?