---
title: "Ownership and data flow in GPUI"
description: "GPUI, Zed's Rust UI framework, sidesteps Rust's single-ownership constraints by having a top-level App own every model and view, while code holds reference-counted Entity<T> handles that can only read or update state when given an App or Context."
url: "https://swe.quest/articles/ownership-and-data-flow-in-gpui-d709f4da05260bf5"
canonical: "https://zed.dev/blog/gpui-ownership"
source: "Zed"
published: "2024-01-25"
difficulty: "medium"
kind: "Deep dive"
reading_minutes: 9
tags: ["rust","frontend","memory-management","event-driven"]
---

# Ownership and data flow in GPUI

A post on [Zed](https://swe.quest/sources/zed.md), published 2024-01-25, 9 min read, Deep dive. Original: [https://zed.dev/blog/gpui-ownership](https://zed.dev/blog/gpui-ownership)

## Summary

GPUI, Zed's Rust UI framework, sidesteps Rust's single-ownership constraints by having a top-level App own every model and view, while code holds reference-counted Entity\<T\> handles that can only read or update state when given an App or Context. Entities communicate via notify/observe and typed emit/subscribe, but calling emit or notify only enqueues an effect; App::update flushes the effect queue after the outermost update, giving run-to-completion semantics without the reentrancy bugs of naive event emitters. To hand out both &mut T and &mut Context\<T\>, update\_entity temporarily leases the entity's state out of the App onto the stack and returns it afterward, at the cost of forbidding reentrant updates to the same entity.

Written by swe.quest, not by the author.

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

## Topics

- [Rust](https://swe.quest/tags/rust.md) (Languages)
- [Frontend](https://swe.quest/tags/frontend.md) (Web & mobile)
- [Memory management](https://swe.quest/tags/memory-management.md) (Compilers & runtimes)
- [Event-driven architecture](https://swe.quest/tags/event-driven.md) (Backend & APIs)

## Prerequisites

- Rust ownership and borrowing ([easy posts on Rust](https://swe.quest/tags/rust.md?difficulty=easy))
- Rc reference counting
- Observer/event emitter pattern

## Keywords

GPUI, Zed, Entity, EventEmitter, Atom

## Related posts

- [Zed Weekly: #25](https://swe.quest/articles/zed-weekly-25-cd3a5f41d4f0b187.md): Zed · 2023-11-03 · Medium · 6 min read · Rust, Frontend, Refactoring & migrations, Developer tools
  Zed is rewriting its UI framework as GPUI 2 and porting the whole editor onto it before open-sourcing, trading feature work for better ergonomics while keeping GPUI 1's performance.
- [Why the big rewrite?](https://swe.quest/articles/why-the-big-rewrite-ec307a4c7f73f459.md): Zed · 2024-01-23 · Easy · 21 min read · Rust, Frontend, Refactoring & migrations, Developer tools
  Zed rewrote its Rust UI framework from GPUI 1 to GPUI 2 because the original design blocked fast UI work: a Flutter-style constraints-down/sizes-up layout model, styles split between Rust element code and TypeScript-generated JSON "themes" loaded at runtime, model code entangled with presentation (a legacy of an early Electron/JSON architecture), and weakly typed geometry (raw f32s and usizes).
- [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.
- [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.
- [This Week at Zed Industries: #16](https://swe.quest/articles/this-week-at-zed-industries-16-c2caea343c027dbd.md): Zed · 2023-08-18 · Medium · 13 min read · Rust, Frontend, Type systems, Developer tools
  Zed has started using its new channels feature internally, where members can message, talk, share screens and co-edit projects, and plans to use it to stream development and host office hours once the editor is open-sourced.

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)
