Files
zed/script
Anthony Eid 90549abcfd gpui: Keep layout nodes between frames (#67222)
GPUI rebuilds Taffy's layout tree every frame, which doesn't take
advantage of Taffy's layout caching. This PR starts fixing that by
persisting layout nodes between frames.

Taffy nodes are paired with the global element ID path they were
requested under, plus their order within it. An element reuses its node
from the last frame, and the node's cached layout is invalidated only
when its style or children changed in a way that affects layout.
Invalidating a node also invalidates its ancestors; its children and its
siblings' subtrees keep their cached layouts.

- Only the layout-affecting fields of `Style` are compared.
- Elements without IDs are matched by order under their nearest ancestor
with one, so inserting or removing one costs its later siblings their
cached layout for that frame.
- Unrequested nodes are kept for one frame for reuse, then removed.
- Measured nodes (text, lists, the editor) are still measured every
frame; the next PR in this stack addresses that.

Testing: a randomized test applies the same changes to two windows, one
keeping its nodes and one rebuilding them every frame, and checks that
they draw the same scene and hitboxes.

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

| Benchmark | Change |
|---|---:|
| Full refresh, trees with paths | −2.2% to −8.2% |
| Full refresh, trees without paths | −8.3% to −19.6% |
| ID churn (no node can be matched) | −1.3% / −3.9% |
| Warm text, 32 panels | −7.3% |
| Scrolling a pane of text rows | −7.9% |
| `uniform_list` scrolling | −5.7% |
| Inspector panel, 500 rows | −7.2% |

Release Notes:

- [GPUI] Improved layout performance by reusing layout nodes between
frames

---------

Co-authored-by: Eric Holk <eric@zed.dev>
2026-11-23 22:31:15 +00:00
..
…
2026-02-24 05:13:04 +00:00
…
…
…
…
…
…
…
…