# Revert "Optimize editor rendering when clipped by parent containers" \(\#45011\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/c1317baebebf955c589ef19d8c209b2ef526f75f)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: c1317baebebf955c589ef19d8c209b2ef526f75f

Requested commit: c1317baebebf955c589ef19d8c209b2ef526f75f

Commit: c1317baebebf955c589ef19d8c209b2ef526f75f

Tree: 8d761cdf88f170280ac4451fce45c5b47f4c521f

Author: Nathan Sobo

Committer: GitHub

## Message

````
Revert "Optimize editor rendering when clipped by parent containers" (#45011)

This reverts commit 914b0117fb5a23469af85e567d5723eca6b53635 (#44995).

The optimization introduced a regression that causes the main thread to
hang for **100+ seconds** in certain scenarios, requiring a force quit
to recover.

## Analysis from spindump

When a large `AutoHeight` editor is displayed inside a `List` (e.g.,
Agent Panel thread view), the clipping calculation can produce invalid
row ranges:

1. `visible_bounds` from `window.content_mask().bounds` represents the
window's content mask, not the intersection with the editor
2. When the editor is partially scrolled out of view,
`clipped_top_in_lines` becomes extremely large
3. This causes `start_row` to be computed as an astronomically high
value
4. `blocks_in_range(start_row..end_row)` then spends excessive time in
`Cursor::search_forward` iterating through the block tree

The spindump showed **~46% of samples** (459/1001 over 10+ seconds)
stuck in `BlockSnapshot::blocks_in_range()`, specifically in cursor
iteration.

### Heaviest stack trace
```
EditorElement::prepaint
  └─ blocks_in_range + 236
       └─ Cursor::search_forward (459 samples)
```

## Symptoms

- Main thread unresponsive for 33-113 seconds before sampling even began
- UI completely frozen
- High CPU usage on main thread (10+ seconds of CPU time in the sample)
- Force quit required to recover

## Path forward

The original optimization goal (reducing line layout work for clipped
editors) is valid, but the implementation needs to:
1. Correctly calculate the **intersection** of editor bounds with the
visible viewport
2. Ensure row calculations stay within valid ranges (clamped to
`max_row`)
3. Handle edge cases where the editor is completely outside the visible
bounds

Release Notes:

- Fixed a hang that could occur when viewing large diffs in the Agent
Panel
````

## Parents

- [3f11cbd62c203857f83252f7e2aa1b073a4b73fb](https://git.cafe/gitcafe/zed/commit/3f11cbd62c203857f83252f7e2aa1b073a4b73fb?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/c1317baebebf955c589ef19d8c209b2ef526f75f?format=markdown)
