# Improve performance of select-all-matches \(\#6700\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 50c3ad963e5bab5225d4b28d891d40b490df0c14

Requested commit: 50c3ad963e5bab5225d4b28d891d40b490df0c14

Commit: 50c3ad963e5bab5225d4b28d891d40b490df0c14

Tree: 39659580d494cf296dcd9df188c111823dc75a09

Author: Thorsten Ball

Committer: GitHub

## Message

```
Improve performance of select-all-matches (#6700)

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

![screenshot-2024-01-25-12 49
32@2x](https://github.com/zed-industries/zed/assets/1185253/9f8ef0fa-a3a7-461c-9ed6-263e48835806)

### Release Notes:

- Improved performance of select-all-matches by factor of ~250
([#6440](https://github.com/zed-industries/zed/issues/6440)).
```

## Parents

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

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

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