Skip to content

perf(errorMessagePrettifier): narrow regex match range#204

Merged
yoavbls merged 1 commit into
yoavbls:mainfrom
progfay:worktree-tuning-regexp
May 1, 2026
Merged

perf(errorMessagePrettifier): narrow regex match range#204
yoavbls merged 1 commit into
yoavbls:mainfrom
progfay:worktree-tuning-regexp

Conversation

@progfay

@progfay progfay commented Apr 26, 2026

Copy link
Copy Markdown
Contributor

related: #139

The (.*) at the beginning of the regular expression on packages/formatter/src/errorMessagePrettifier.ts#L128 was matching characters that were passed through unchanged (just concatenated as-is to the output).

/(.*)[']([^>]*)['] (type|interface|return type|file|module|is (not )?assignable)/gi,

In this PR, I improved inefficient matching by narrowing the match to cover only the portion that is actually transformed.

@kevinramharak kevinramharak requested a review from yoavbls April 27, 2026 12:21
@kevinramharak

kevinramharak commented Apr 27, 2026

Copy link
Copy Markdown
Collaborator

I think this is correct, the initial capture doesn't do anything besides causing backtracking once the later parts are matched. And the capture isn't transformed in the replacer function either. Doubt it will be noticeable, but it should technically reduce the work done, and remove another backtracking source in case any (highly unlikely) regex dos attempts are made.

@yoavbls yoavbls merged commit 08aaca2 into yoavbls:main May 1, 2026
1 check passed
@progfay progfay deleted the worktree-tuning-regexp branch May 1, 2026 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants