Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Zed 11 min read Deep dive mediumAdept

Async Rust

Zed's GPUI framework runs async Rust without tokio or smol: it uses async_task for tasks and thin wrappers around macOS Grand Central Dispatch as the executor, dispatching Runnables via dispatch_async_f onto the main queue or a high-priority global queue through a trampoline function. GPUI separates a ForegroundExecutor (main thread, which handles rendering and input and must never block) from a BackgroundExecutor (GCD global queue). Code walkthroughs from the editor, terminal search and project-wide search show the pattern of keeping quick work on the main thread and pushing lock acquisition, file scanning and searching to background tasks so frames hit the 8ms budget at 120 FPS.

Assumes: async Rust futuresRust Arc and MutexUI main thread model

Related posts

  • Zed Weekly: #29

    Zed mediumAdept

    Zed's port to GPUI 2 is nearing daily usability, and the team is focused on frame-rendering performance measured by holding tab-switch at 60Hz key repeat. Because every element is a boxed trait object, they replaced malloc with a custom thread-local bump arena that enforces safety dynamically instead of via lifetimes, and changed `Element::paint` to take `&mut self` to avoid heap-to-stack copies. The target is full-window redraws under 4ms on an M1, with view caching planned next. Other updates cover a better VS Code theme importer, focus handlers moved to run after each frame draw to fix a split-pane focus bug, and a port of the feedback UI.

  • Zed Weekly: #22

    Zed easyNovice

    Zed team members report weekly progress: GPUI is being rewritten with a ported Metal renderer that uses plane-split for primitive draw ordering, multi-threaded entity access, and a MainThread<T: Context> wrapper so native UI APIs are only called from the main thread. Channels are being reworked to separate chat-style communication from DAG-structured project notes, with unread indicators, notifications, public channels and deep links on the way. Julia split markdown parsing from rendering for completion documentation, avoiding flicker when grammars load late and speeding up rendering. Other work covers Vue LSP and tree-sitter support, CPU and memory telemetry, and a fix for a follow-loop bug in collaboration.

  • Leveraging Rust and the GPU to render user interfaces at 120 FPS

    Zed hardMaster

    Zed's GPUI framework hits 120 FPS by rendering the editor UI like a video game: rather than a general-purpose 2D vector renderer (Pathfinder proved too slow), it uses dedicated GPU shaders for a small set of primitives such as rectangles, shadows, text, icons and images, all described as data on the CPU and drawn with instanced rendering. Rounded rectangles come from a signed distance function evaluated in a Metal fragment shader. Drop shadows follow Evan Wallace's approximation, which pairs a closed-form erf-based Gaussian convolution on one axis with a few samples along the other. Text uses OS shaping via CoreText, with a per-frame cache of text-font pairs so only changed text gets reshaped.

  • Optimizing the Metal pipeline to maintain 120 FPS in GPUI

    Zed mediumAdept

    Zed's GPUI renderer dropped frames on Macs running in direct (non-composited) mode because `MetalRenderer::draw` blocked the main thread with `wait_until_completed`. In direct mode that call waits for pixels to reach the frame buffer, not just the compositor's intermediate surface. Switching to `wait_until_scheduled` exposed a CPU/GPU race on the shared instance buffer, fixed with a pool of instance buffers that are returned to the pool from a command-buffer completion handler. Dropped frames under ProMotion were fixed by presenting repeated frames for one second after the last input so the display stays at 120 Hz. When macOS later capped some users at 60 FPS, the team moved to `CVDisplayLink`, presents drawables via the command buffer without `presentsWithTransaction`, and keeps the synchronous path only for app startup and window resizes.

  • We Have to Start Over: From Atom to Zed

    Zed easyNovice

    Zed's co-founders explain why they abandoned Atom's Electron/JavaScript stack and rebuilt a code editor in Rust: JavaScript's pointer-chasing arrays, uncontrollable GC pauses, and the costly JS/C++ boundary for multithreading made performance work feel like fighting the platform. Rust's ownership model pushed them toward a copy-on-write B-tree (SumTree) rope built on Arc, letting snapshots move to background threads in O(1), and high-level Rust code cut a find-all-matches operation from 1s to 4ms. GPU rendering with custom shaders and signed distance fields came out of necessity after Pathfinder proved too slow. Owning the stack (Tree-sitter, GPUI) lets them change anything, such as adding WASM language extensions, at the cost of building more themselves.

The quest for software engineering knowledge.

Look:
Layout: