Skip to content

Fix text finder crash from unbounded memory use#60377

Open
davidalecrim1 wants to merge 1 commit into
zed-industries:mainfrom
davidalecrim1:fix/text-finder-minified-oom-60238
Open

Fix text finder crash from unbounded memory use#60377
davidalecrim1 wants to merge 1 commit into
zed-industries:mainfrom
davidalecrim1:fix/text-finder-minified-oom-60238

Conversation

@davidalecrim1

@davidalecrim1 davidalecrim1 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Solution

  • Stop storing line text on matches. Each match now keeps only its position and column, and the text shown in a row is built lazily for the visible rows, using a bounded slice around the match rather than the whole line. Line boundaries come from the buffer's line index instead of re-scanning the content per match.
  • Cap the number of matches the finder builds while streaming results, using the same ceiling project search already applies. This keeps the finder from ever assembling an unbounded match list on the UI thread.
  • Behavior is unchanged: every occurrence is still its own row, jumping to a match lands on the exact line and column, and the rendered text and highlighting look the same. The finder just no longer holds text proportional to the match count.

Testing

  • Added tests covering the new behavior: the match count is capped while streaming, every occurrence below the ceiling still becomes its own match at the correct line and column, and the rendered slice around a match stays bounded on a huge line while still covering a whole short line.
  • Verified by hand with the reproduction from the issue. The screenshot below shows the memory usage and the matching against the issue data:
Screenshot 2026-07-03 at 17 43 11

Self-Review Checklist:

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content adheres to Zed's UI standards (UX/UI and icon guidelines)
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable

Release Notes:

  • Fixed a crash and high memory usage in the text finder.

The text finder copied the full matched line into every match it kept,
so memory grew with match count times line size and could climb into the
tens of gigabytes and crash. Store only each match's position and column,
render a bounded slice of the line lazily for visible rows, and cap the
number of matches built while streaming using project search's existing
ceiling.

Fixes zed-industries#60238.
@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

After executing the command text finder:toggle, the Zed editor will freeze.

1 participant