Skip to content

diff: translate -F/-p groups to non-capturing groups - #376

Merged
sylvestre merged 1 commit into
uutils:mainfrom
binhvq:bre-non-capturing-groups
Nov 11, 2026
Merged

sylvestre merged 1 commit into
uutils:mainfrom
binhvq:bre-non-capturing-groups

Conversation

@binhvq

@binhvq binhvq commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Fixes #350.

\( was translated to a capturing (, but we only call is_match() and back references are rejected, so the captures are never read. Emit (?: instead.

With the pattern from the issue, peak RSS goes from ~177 MB to ~7 MB here (GNU diff: ~17 MB).

Added a unit test that the compiled regex has no capture groups.

Only is_match() is called and back references are rejected, so nothing reads the captures, yet the regex engine kept slots for every group. A pattern with many repeated groups used over ten times the memory it needs.
@sylvestre
sylvestre merged commit 0d7096a into uutils:main Nov 11, 2026
31 checks passed
@sylvestre

Copy link
Copy Markdown
Collaborator

Thanks for your PR

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.

diff - -F/-p regex groups are compiled as capturing groups and use 10x+ memory

2 participants