-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
terminal: Fix performance issues with hyperlink regex matching #44407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Problem statement: When given a line that contained a lot of matches of your hyperlink regex of choice (thanks to , we would look for matches that intersected with currently hovered point. This is *hella* expensive, because we would re-walk the whole alacritty grid for each match. With the repro that Joseph shared, we had to go through 4000 such matches on each frame render. Problem solution: We now convert the hovered point into a range within the line in order to throw away matches that do not intersect the hovered range. This lets us avoid performing the unnecessary conversion when we know it's never going to yield a match range that intersects the hovered point.
…termine skippability
Co-authored-by: Dave Waggoner <waggoner.dave@gmail.com>
50e1fb3 to
b133d08
Compare
davewa
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thanks for finding and fixing this regression, I'll be adding a perf test for this scenario soon in a separate PR.
|
@davewa thanks for a thorough review! |
|
/cherry-pick preview |
Problem statement: When given a line that contained a lot of matches of your hyperlink regex of choice (thanks to #40305), we would look for matches that intersected with currently hovered point. This is *hella* expensive, because we would re-walk the whole alacritty grid for each match. With the repro that Joseph shared, we had to go through 4000 such matches on each frame render. Problem solution: We now convert the hovered point into a range within the line (byte-wise) in order to throw away matches that do not intersect the hovered range. This lets us avoid performing the unnecessary conversion when we know it's never going to yield a match range that intersects the hovered point. Release Notes: - terminal: Fixed performance regression when handling long lines. --------- Co-authored-by: Dave Waggoner <waggoner.dave@gmail.com>
… (cherry-pick to preview) (#44423) Cherry-pick of #44407 to preview ---- Problem statement: When given a line that contained a lot of matches of your hyperlink regex of choice (thanks to #40305), we would look for matches that intersected with currently hovered point. This is *hella* expensive, because we would re-walk the whole alacritty grid for each match. With the repro that Joseph shared, we had to go through 4000 such matches on each frame render. Problem solution: We now convert the hovered point into a range within the line (byte-wise) in order to throw away matches that do not intersect the hovered range. This lets us avoid performing the unnecessary conversion when we know it's never going to yield a match range that intersects the hovered point. Release Notes: - terminal: Fixed performance regression when handling long lines. --------- Co-authored-by: Dave Waggoner <waggoner.dave@gmail.com> Co-authored-by: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Co-authored-by: Dave Waggoner <waggoner.dave@gmail.com>
|
/cherry-pick stable |
|
🍒💥 Cherry-pick did not succeed |
…ndustries#44407) Problem statement: When given a line that contained a lot of matches of your hyperlink regex of choice (thanks to zed-industries#40305), we would look for matches that intersected with currently hovered point. This is *hella* expensive, because we would re-walk the whole alacritty grid for each match. With the repro that Joseph shared, we had to go through 4000 such matches on each frame render. Problem solution: We now convert the hovered point into a range within the line (byte-wise) in order to throw away matches that do not intersect the hovered range. This lets us avoid performing the unnecessary conversion when we know it's never going to yield a match range that intersects the hovered point. Release Notes: - terminal: Fixed performance regression when handling long lines. --------- Co-authored-by: Dave Waggoner <waggoner.dave@gmail.com>
Related to: - #44510 - #44407 Previously we were searching for hyperlinks on every scroll, even if Cmd was not held. With this PR, - We only search for hyperlinks on scroll if Cmd is held - We now clear `last_hovered_word` in all cases where Cmd is not held - Renamed `word_from_position` -> `schedule_find_hyperlink` - Simplified logic in `schedule_find_hyperlink` Performance measurements The test scrolls up and down 20,000x in a loop. However, since this PR is just removing a code path that was very dependent on the length of the line in terminal, it's not super meaningful as a comparison. The test uses a line length of "long line ".repeat(1000), and in main the performance is directly proportional to the line length, so for benchmarking it in main it only scrolls up and down 20x. I think all that is really useful to say is that currently scrolling is slow, and proportional to the line length, and with this PR it is buttery-smooth and unaffected by line length. I've included a few data points below anyway. At least the test can help catch future regressions. | Branch | Command | Scrolls | Iter/sec | Mean [ms] | SD [ms] | Iterations | Importance (weight) | |:---|:---|---:|---:|---:|---:|---:|---:| | main | tests::perf::scroll_long_line_benchmark | 40 | 16.85 | 712.00 | 2.80 | 12 | average (50) | | this PR | tests::perf::scroll_long_line_benchmark | 40 | 116.22 | 413.60 | 0.50 | 48 | average (50) | | this PR | tests::perf::scroll_long_line_benchmark | 40,000 | 9.19 | 1306.40 | 7.00 | 12 | average (50) | | only overhead | tests::perf::scroll_long_line_benchmark | 0 | 114.29 | 420.90 | 2.00 | 48 | average (50) | Release Notes: - terminal: Improved scroll performance
…ndustries#44407) Problem statement: When given a line that contained a lot of matches of your hyperlink regex of choice (thanks to zed-industries#40305), we would look for matches that intersected with currently hovered point. This is *hella* expensive, because we would re-walk the whole alacritty grid for each match. With the repro that Joseph shared, we had to go through 4000 such matches on each frame render. Problem solution: We now convert the hovered point into a range within the line (byte-wise) in order to throw away matches that do not intersect the hovered range. This lets us avoid performing the unnecessary conversion when we know it's never going to yield a match range that intersects the hovered point. Release Notes: - terminal: Fixed performance regression when handling long lines. --------- Co-authored-by: Dave Waggoner <waggoner.dave@gmail.com>
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
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
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
…ustries#44721) Related to - zed-industries#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 zed-industries#44407 and zed-industries#44510 - Simplifies the logic added in zed-industries#44407 Performance measurements For the scenario from zed-industries#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
…ustries#44721) Related to - zed-industries#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 zed-industries#44407 and zed-industries#44510 - Simplifies the logic added in zed-industries#44407 Performance measurements For the scenario from zed-industries#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
Problem statement: When given a line that contained a lot of matches of
your hyperlink regex of choice (thanks to #40305), we would look for matches
that intersected with currently hovered point. This is hella
expensive, because we would re-walk the whole alacritty grid for each
match. With the repro that Joseph shared, we had to go through 4000 such
matches on each frame render.
Problem solution: We now convert the hovered point into a range within
the line (byte-wise) in order to throw away matches that do not intersect the
hovered range. This lets us avoid performing the unnecessary conversion
when we know it's never going to yield a match range that intersects the
hovered point.
Release Notes: