Skip to content

Only make the --js numbers the code uses, and only count files for $i and $c to close #814 - #830

Merged
mathiasrw merged 14 commits into
mainfrom
fix/814
Oct 23, 2026
Merged

mathiasrw merged 14 commits into
mainfrom
fix/814

Conversation

@mathiasrw

@mathiasrw mathiasrw commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

Closes #814

Stacked on #829.

Change

The numbers of #791 cost time also in runs that do not use them:

  • The code put in front of the --js code now only makes the numbers the code uses. Before, about 120 variables were made for each match when the code ran once per match.
  • The files are no longer searched one more time to count them for $i and $c. A file counts for $i when the code runs for a match in it, and for $c when its content changed, both known as the file is worked on. Before, every file was searched again in every run, also without --js.

rexreplace '(foo)' '$1.toUpperCase()' m.txt --js -o with 20,000 matches, Bun on a Mac:

Time
Before 2.09 s
Now 0.09 s
Now, with code that uses $M 0.75 s

Tests

yarn test-ci passes, and the tests of #791 still pass. There is no new test of the speed, as it would be flaky in CI.

From the review of 23 October.

After the review of 24 October

  • The help of --js says that a number is only made when the code names it, so a name built when the code runs, like eval('$' + 'n'), is not there.
  • The text above no longer says that this can not be seen from the code.

Follow-up

The --js help says it shorter, and the sentence on once per match is folded into it: "For speed, only the numbers the code names are made, and the code runs once per file unless it names the match, a group, $m or $M. This is found with a simple text search, so it can be fooled, like by eval('$' + 'n')." The README line is in #838.

Follow-up

All the numbers are made every time, as values of the function that runs the code, and not as var code put in front of it. So they cost nothing to compile:

20 000 matches, (foo) $1.toUpperCase() Time
Before #791 (from the issue) 0.22 s
main 1.91 s
This PR 0.22 s

$i is counted when the code runs for a match in the file, so there is no extra search of each file.

The help says only: "For speed, the code runs once per file unless it names the match, a group, $m or $M."

test/fix/814.test.js is new: a file with no match is skipped by $i and $c.

@mathiasrw
mathiasrw marked this pull request as ready for review October 23, 2026 13:15
@mathiasrw
mathiasrw added this pull request to stack #841 October 23, 2026 13:56
@mathiasrw
mathiasrw marked this pull request as draft October 23, 2026 14:58
@mathiasrw
mathiasrw marked this pull request as ready for review October 23, 2026 15:02
@mathiasrw
mathiasrw removed this pull request from stack #841 October 23, 2026 15:57
@mathiasrw
mathiasrw added this pull request to stack #849 October 23, 2026 16:12
@mathiasrw
mathiasrw marked this pull request as draft October 23, 2026 16:12
@mathiasrw
mathiasrw removed this pull request from stack #849 October 23, 2026 16:12
@mathiasrw
mathiasrw changed the base branch from fix/824 to main October 23, 2026 16:13
@mathiasrw
mathiasrw marked this pull request as ready for review October 23, 2026 16:15
@mathiasrw
mathiasrw added this pull request to stack #850 October 23, 2026 16:17
@mathiasrw
mathiasrw marked this pull request as draft October 23, 2026 16:22
@mathiasrw
mathiasrw marked this pull request as ready for review October 23, 2026 16:29
@mathiasrw
mathiasrw merged commit 549752e into main Oct 23, 2026
7 checks passed
@mathiasrw
mathiasrw deleted the fix/814 branch October 23, 2026 16:53
mathiasrw added a commit that referenced this pull request Oct 23, 2026
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.

Fix the --js numbers slowing down runs that do not use them

1 participant