Skip to content

Conversation

@ConradIrwin
Copy link
Member

Fancy regex has a max backtracking limit which defaults to 1,000,000
backtracks. This avoids spinning the CPU forever in the case that a
match is taking a long time (though does mean that some matches may be
missed).

Unfortunately the verison we depended on causes an infinite loop when
the backtracking limit is hit
(fancy-regex/fancy-regex#137), so we got the
worse of both worlds: matches were missed and we spun the CPU forever.

Updating fixes this.

Excitingly regex may gain support for lookarounds
(rust-lang/regex#1315), which will make
fancy-regex much less load bearing.

Closes #43821

Release Notes:

  • Fix a bug where search regexes with look-around or backreferences could hang
    the CPU. They will now abort after a certain number of match attempts.

Fancy regex has a max backtracking limit which defaults to 1,000,000
backtracks. This avoids spinning the CPU forever in the case that a
match is taking a long time (though does mean that some matches may be
missed).

Unfortunately the verison we depended on causes an infinite loop when
the backtracking limit is hit
(fancy-regex/fancy-regex#137), so we got the
worse of both worlds: matches were missed *and* we spun the CPU forever.

Updating fixes this.

Excitingly, in the future, regex may gain support for lookarounds
(rust-lang/regex#1315), which will make
fancy-regex much less load bearing.

Closes #43821
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Dec 4, 2025
@zed-industries-bot
Copy link

Messages
📖

This PR includes links to the following GitHub Issues: #fancy-regex/fancy-regex#137
If this PR aims to close an issue, please include a Closes #ISSUE line at the top of the PR body.

Generated by 🚫 dangerJS against 999ab03

@ConradIrwin ConradIrwin enabled auto-merge (squash) December 4, 2025 07:20
@ConradIrwin ConradIrwin merged commit 1e4d80a into main Dec 4, 2025
24 checks passed
@ConradIrwin ConradIrwin deleted the fancy-regex-update branch December 4, 2025 07:29
baldwindavid added a commit to baldwindavid/zed that referenced this pull request Dec 4, 2025
* main: (155 commits)
  Add support for git remotes (zed-industries#42819)
  python: Improve sorting order of toolchains to give higher precedence to project-local virtual environments that are within current subproject (zed-industries#44141)
  Use buffer language when formatting with Prettier (zed-industries#43368)
  search: Fix sort order not being maintained in presence of open buffers (zed-industries#44135)
  bedrock: Support global endpoints and new regional endpoints (zed-industries#44103)
  linux: Spawn at least two background threads (zed-industries#44110)
  macos: Add missing file access entitlements (zed-industries#43609)
  Re-colorize the brackets when the theme changes (zed-industries#44130)
  Reduce priority of Windows thread pool work items (zed-industries#44121)
  Update fancy-regex (zed-industries#44120)
  Prefer to disable options over hiding (git panel entry context menu) (zed-industries#44102)
  tab_switcher: Subscribe to workspace events instead of pane events (zed-industries#44101)
  editor: Add active match highlight for buffer and project search (zed-industries#44098)
  Add more preview tab settings and fix janky behavior (zed-industries#43921)
  ai: Add an eval for the inline assistant (zed-industries#43291)
  Fix circular reference issue around PopoverMenu again (zed-industries#44084)
  Run `git2::Repository::find_remote` in the background (zed-industries#44092)
  Improve support for multiple registrations of  `textDocument/diagnostic` (zed-industries#43703)
  Revert "http_client: Add integrity checks for GitHub binaries using digest checks (zed-industries#43737)" (zed-industries#44086)
  editor: Fix blame hover not working when inline git blame is disabled (zed-industries#42992)
  ...
AlpSha pushed a commit to AlpSha/zed that referenced this pull request Dec 5, 2025
Fancy regex has a max backtracking limit which defaults to 1,000,000
backtracks. This avoids spinning the CPU forever in the case that a
match is taking a long time (though does mean that some matches may be
missed).

Unfortunately the verison we depended on causes an infinite loop when
the backtracking limit is hit
(fancy-regex/fancy-regex#137), so we got the
worse of both worlds: matches were missed *and* we spun the CPU forever.

Updating fixes this.

Excitingly regex may gain support for lookarounds
(rust-lang/regex#1315), which will make
fancy-regex much less load bearing.

Closes zed-industries#43821

Release Notes:

- Fix a bug where search regexes with look-around or backreferences
could hang
  the CPU. They will now abort after a certain number of match attempts.
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.

Zed CPU usage uncapped when parsing complex regular expressions; freezes computer

3 participants