Anthony Eid 79af38b26c gpui: Keep measured layouts while their inputs are unchanged (#67223)
With layout nodes kept between frames, a node sized by a measure
function still can't stay cached: the function is a new closure every
frame, so there is no way to tell whether it would measure the same
sizes. That covers every text element, and invalidating one invalidates
its ancestors too.

This adds `Window::request_keyed_measured_layout`, which takes a key
describing everything the measured size depends on. While the key equals
the one the node was last measured with, Taffy's cached sizes are kept
and the measure function isn't called. `request_measured_layout` is
unchanged and still measures every frame. On steady-state frames,
same-type measure contexts are updated in place to avoid allocating and
freeing a `Box` per measured node per frame.

Text elements use it. Their key is the text, runs, text style, font
size, line height, scale factor, and the text system's font generation.
Unchanged text takes over the lines it shaped last frame and paints from
those, so it is neither measured nor shaped again.

- Text is measured from its own inputs alone, and only `PerformLayout`
(not sizing probes) replaces the lines kept for painting.
- The line layout cache keeps layouts that an element still holds even
in frames that don't shape them, and now includes `max_lines`
(`line_clamp`) in its cache key.
- `TaffyLayoutEngine` clears its layout cache when a window's
`scale_factor` changes so device-pixel cached measurements (such as
`list` and `uniform_list`) never go stale across displays.
- `list` and `uniform_list` key their `ListSizingBehavior::Infer`
measurements.

Testing:
- Targeted tests verify that keyed leaves and text elements are measured
again only when their inputs change (including `TextSystem::add_fonts`),
that keyed leaves update on `scale_factor` changes, and that
`LineLayoutCache` distinguishes `max_lines`.
- Expanded `RandomizedElementTree` and
`layout_cache_matches_rebuilding_every_frame` to cover flex, grid,
absolute positioning, `Display::None`, `with_rem_size`, single-field
mutations, root inherited text styles and scope changes, deferred
anchored popups, `StyledText`/`InteractiveText` with mouse moves,
keyed/unkeyed measured leaves, and scrolling `list`/`uniform_list` (128
seeds / 6,144 frames verified locally).

Performance: instructions per frame against `main` in the GPUI
benchmarks (`script/gpui-bench-compare`), including the previous PR.
These are synthetic trees, not Zed scenarios.

| Benchmark | Previous PR | With this PR |
|---|---:|---:|
| Full refresh, trees with paths | −2.2% to −8.2% | −3.0% to −32% |
| Full refresh, trees without paths | −8.3% to −19.6% | −22% to −34% |
| ID churn (no node can be matched) | −1.3% / −3.9% | −1.1% / −2.8% |
| Warm text, 32 panels | −7.3% | −38.6% |
| First populated text frame | −4.3% | −4.1% |
| Scrolling a pane of text rows | −7.9% | −57.2% |
| `uniform_list` scrolling | −5.7% | −27.5% |
| Inspector panel, 500 rows | −7.2% | −52.4% |

Release Notes:

- [GPUI] Added `Window::request_keyed_measured_layout`, which keeps a
measured element's size while its key is unchanged
- Improved layout performance in Zed's renderer
2026-11-24 09:49:03 +00:00
…
…
2026-11-17 12:43:21 +00:00
…
2026-11-23 12:06:38 +00:00
…
…
…
…

Zed

Zed CI

Welcome to Zed, a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.


Installation

On macOS, Linux, and Windows you can download Zed directly or install Zed via your local package manager (macOS/Linux/Windows).

Other platforms are not yet available:

Developing Zed

Contributing

See CONTRIBUTING.md for ways you can contribute to Zed.

Also... we're hiring! Check out our jobs page for open roles.

Licensing

Zed source code is licensed primarily under GPL-3.0-or-later, with Apache-2.0 components where marked.

License information for third party dependencies must be correctly provided for CI to pass.

We use cargo-about to automatically comply with open source licenses. If CI is failing, check the following:

  • Is it showing a no license specified error for a crate you've created? If so, add publish = false under [package] in your crate's Cargo.toml.
  • Is the error failed to satisfy license requirements for a dependency? If so, first determine what license the project has and whether this system is sufficient to comply with this license's requirements. If you're unsure, ask a lawyer. Once you've verified that this system is acceptable add the license's SPDX identifier to the accepted array in script/licenses/zed-licenses.toml.
  • Is cargo-about unable to find the license for a dependency? If so, add a clarification field at the end of script/licenses/zed-licenses.toml, as specified in the cargo-about book.

Sponsorship

Zed is developed by Zed Industries, Inc., a for-profit company.

If you’d like to financially support the project, you can do so via GitHub Sponsors. Sponsorships go directly to Zed Industries and are used as general company revenue. There are no perks or entitlements associated with sponsorship.

S
Description
No description provided
Readme 1.4 GiB
Languages
Rust 95.4%
JSON-with-Comments 2.4%
Python 0.8%
Inno Setup 0.3%
Tree-sitter Query 0.3%
Other 0.4%