# terminal: Improve regex hyperlink performance for long lines \(\#44721\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 8aab646aeca1b4698737fbd8d0efa29caf87ee8c

Requested commit: 8aab646aeca1b4698737fbd8d0efa29caf87ee8c

Commit: 8aab646aeca1b4698737fbd8d0efa29caf87ee8c

Tree: e9e1a651d70056557afdcd6c66593d16a71eb8a6

Author: Dave Waggoner

Committer: GitHub

## Message

```
terminal: Improve regex hyperlink performance for long lines (#44721)

Related to
- #44407

This PR further improves performance for regex hyperlink finding by
eliminating unnecessary regex matching. Currently, we repeatedly search
for matches from the start of the line until the match contains the
hovered point. This is only required to support custom regexes which
match strings containing spaces, with multiple matches on a single line.
This isn't actually a useful scenario, and is no longer supported. This
PR changes to only search twice, the first match starting from the start
of the line, and the hovered word (space-delimited). The most dramatic
improvement is for long lines with many words.

In addition to the above changes, this PR:
- Adds test for the scenarios from #44407 and #44510 
- Simplifies the logic added in #44407

Performance measurements

For the scenario from #44407, this improves the perf test's iteration
time from 1.22ms to 0.47ms.

main:

| Branch | Command | Iter/sec | Mean [ms] | SD [ms] | Iterations |
Importance (weight) |
|:---|:---|---:|---:|---:|---:|---:|
| main |
terminal_hyperlinks::tests::path::perf::pr_44407_hyperlink_benchmark |
819.64 | 937.60 | 2.20 | 768 | average (50) |
| this PR |
terminal_hyperlinks::tests::path::perf::pr_44407_hyperlink_benchmark |
2099.79 | 1463.20 | 7.20 | 3072 | average (50) |

Release Notes:

- terminal: Improve path hyperlink performance for long lines
```

## Parents

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

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