# Improve performance of select-all-matches · gitcafe/zed

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

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

Visibility: public

Requested revision: 0a78c676475d8e3ca3d569f22e8bce0d3291cff5

Requested commit: 0a78c676475d8e3ca3d569f22e8bce0d3291cff5

Commit: 0a78c676475d8e3ca3d569f22e8bce0d3291cff5

Tree: 7567d9036e00fea0d2fbbe8a2daa026ce2621c06

Author: Thorsten Ball

Committer: Thorsten Ball

## Message

```
Improve performance of select-all-matches

This fixes #6440.

The previous approach was calling select-next-match in a loop, which
leaves optimizations on the table when you already know that you want to
select all of the matches.

So what we did here is to optimize the code for the "give me all
matches" case:

1. Find all results in the current buffer
2. Build up *all* selections
3. Sort selections & throw away overlapping ones (keep oldest)
4. Unfold if necessary
5. Render selections

On my M3 Max searching for `<span` in the test file [1] from the ticket,
it

previously took: ~1.07s
now takes: ~4ms

[1]: https://github.com/standardebooks/edgar-allan-poe_poetry/blob/master/src/epub/text/poetry.xhtml

Co-authored-by: Antonio <antonio@zed.dev>

```

## Parents

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

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