---
title: "Optimizing the Metal pipeline to maintain 120 FPS in GPUI"
description: "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`."
url: "https://swe.quest/articles/optimizing-the-metal-pipeline-to-maintain-120-fps-in-gpui-951f2f761e0fc50d"
canonical: "https://zed.dev/blog/120fps"
source: "Zed"
published: "2024-02-07"
difficulty: "medium"
kind: "Case study"
reading_minutes: 9
tags: ["performance","frontend","rust","hardware","debugging"]
---

# Optimizing the Metal pipeline to maintain 120 FPS in GPUI

A post on [Zed](https://swe.quest/sources/zed.md), published 2024-02-07, 9 min read, Case study. Original: [https://zed.dev/blog/120fps](https://zed.dev/blog/120fps)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Frontend](https://swe.quest/tags/frontend.md) (Web & mobile)
- [Rust](https://swe.quest/tags/rust.md) (Languages)
- [Hardware](https://swe.quest/tags/hardware.md) (Infrastructure)
- [Debugging](https://swe.quest/tags/debugging.md) (Engineering practices)

## Prerequisites

- GPU command buffers ([easy posts on Hardware](https://swe.quest/tags/hardware.md?difficulty=easy))
- macOS AppKit/CoreAnimation basics
- frame pacing and vsync

## Keywords

GPUI, Zed, Metal, CAMetalLayer, CADisplayLink, CVDisplayLink, ProMotion

## Related posts

- [Zed Weekly: #29](https://swe.quest/articles/zed-weekly-29-41f27bba860d0170.md): Zed · 2023-12-15 · Medium · 6 min read · Rust, Memory management, Performance engineering, Frontend, Developer tools
  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.
- [Leveraging Rust and the GPU to render user interfaces at 120 FPS](https://swe.quest/articles/leveraging-rust-and-the-gpu-to-render-user-interfaces-at-120-fps-8175e9071db5a167.md): Zed · 2023-03-07 · Hard · 16 min read · Performance engineering, Rust, Frontend, Hardware, Developer tools
  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.
- [Zed Weekly: #22](https://swe.quest/articles/zed-weekly-22-1c922abde503e316.md): Zed · 2023-10-06 · Easy · 7 min read · Developer tools, Rust, Real-time systems, Product engineering
  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.
- [Async Rust](https://swe.quest/articles/async-rust-c6376cf98e387782.md): Zed · 2024-04-09 · Medium · 11 min read · Rust, Concurrency, Runtimes & VMs, Developer tools, Performance engineering
  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.
- [The Future of React Native Graphics: WebGPU, Skia, and Beyond](https://swe.quest/articles/the-future-of-react-native-graphics-webgpu-skia-and-beyond-c599058475fc1e90.md): Shopify Engineering · 2025-06-20 · Easy · 7 min read · React, Mobile, Performance engineering
  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.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
