Skip to content

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

Zed 9 min read Case study mediumAdept

Optimizing the Metal pipeline to maintain 120 FPS in GPUI

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.

Assumes: GPU command buffersmacOS AppKit/CoreAnimation basicsframe pacing and vsync

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.

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

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

  • Async Rust

    Zed mediumAdept

    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.

  • The Future of React Native Graphics: WebGPU, Skia, and Beyond

    Shopify Engineering easyNovice

    React Native WebGPU, built on Google's Dawn, lets React Native apps run Three.js, React Three Fiber, TSL shaders, ComputeToys compute shaders and TensorFlow.js on Metal (iOS) and Vulkan (Android) with no changes, which collapses the separate OpenGL and Metal backends into one. Lessons from that work fed back into React Native Skia. Moving from a mutable C++ scene graph (SkiaDOM) to an immutable, Fabric-reconciler display list made animation up to 50% faster on iOS and nearly 200% faster on Android, while fixing 98% of reported Android crashes. Skia also gained macOS, tvOS and headless Node.js targets, and the experimental Skia Graphite backend previews automatic threading and two-way 2D/3D texture composition.

The quest for software engineering knowledge.

Look:
Layout: