⚡️ Faster fc.stringMatching on generate#7054
Merged
Merged
Conversation
The problem got detected by Claude on #7044 but the fix was really targeting a sub-part of the problem. This fix address a way larger range and thus make `fc.stringMatching` even faster and in even more cases. The issues was that a regex such as `/^abc$/` was resulting into a tuple of 5 constants: '', 'a', 'b', 'c', '' to be spawned on fast-check side. Actually it could have be summarized by just one 'abc'. This PR tries to merge together consecutive chars before creating and calling the constant arbitraries in the case of an Alternative regex node.
🦋 Changeset detectedLatest commit: 11af42c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@fast-check/ava
fast-check
@fast-check/jest
@fast-check/packaged
@fast-check/poisoning
@fast-check/vitest
@fast-check/worker
commit: |
Contributor
⏱️ Benchmark ResultsClick to expand |
dubzzz
enabled auto-merge (squash)
June 6, 2026 22:17
dubzzz
disabled auto-merge
June 6, 2026 23:11
Owner
Author
|
The change also add better support for shrink capabilities on Alternative case |
5 tasks
## Description > AI-agent disclosure: this PR was authored by an automated agent (Claude Code) and has not been line-by-line reviewed by a human before submission. This PR targets the `faster-stringmatching` branch (PR #7054). The `fc.stringMatching` generate speedup changes the values produced for a given seed, which makes the `stringMatching` no-regression snapshots stale. This refreshes them so the e2e suite passes on top of that work. For end users this carries no behavioral change of its own — it only re-records the expected outputs of `fc.stringMatching` so the no-regression guardrails reflect the new (still valid) generated values. The two affected snapshots are `stringMatching` and `stringMatching({maxLength:10})` in `test/e2e/NoRegression.spec.ts`; their generated emails now match the updated generation path. No other no-regression snapshots changed, and `NoRegressionStack.spec.ts` was unaffected. Impact level: this is a test-only change (no library code), so it does not warrant a changeset of its own — it belongs with the perf PR it stacks on. Scope is a single concern: regenerating the no-regression snapshots invalidated by the stringMatching change. Snapshots were produced via `vitest -u` and verified by re-running `test/e2e/NoRegression.spec.ts` (85 passing) and `test/e2e/NoRegressionStack.spec.ts` (6 passing). These snapshots would have failed against the speedup without this update — that mismatch is exactly what this PR resolves. Fixes #issue-number <!-- Add any additional context here --> ## Checklist — _Don't delete this checklist and make sure you do the following before opening the PR_ - [ ] I have a full understanding of every line in this PR — whether the code was hand-written, AI-generated, copied from external sources or produced by any other tool - [ ] I flagged the impact of my change (minor / patch / major) either by running `pnpm run bump` or by following the instructions from the changeset bot - [ ] I kept this PR focused on a single concern and did not bundle unrelated changes - [ ] I followed the [gitmoji](https://gitmoji.dev/) specification for the name of the PR, including the package scope (e.g. `🐛(vitest) Something...`) when the change targets a package other than `fast-check` - [ ] I added relevant tests and they would have failed without my PR (when applicable) <!-- PRs not checking all the boxes may take longer before being reviewed --> <!-- More about contributing at https://github.com/dubzzz/fast-check/blob/main/CONTRIBUTING.md --> --- _Generated by [Claude Code](https://claude.ai/code/session_011nEBy7JcAAQ1nnYK1hvLhF)_ Co-authored-by: Claude <[email protected]>
dubzzz
enabled auto-merge (squash)
June 6, 2026 23:16
dubzzz
commented
Jun 6, 2026
5 tasks
## Description > AI-agent disclosure: this PR was authored by an automated agent (Claude Code) and has not been line-by-line reviewed by a human before submission. This PR targets the `faster-stringmatching` branch (PR #7054). The latest commit on that branch resets `pendingAggregatedValue` in `stringMatching.ts`, which corrects the values produced by `fc.stringMatching` for a given seed. This refreshes the `stringMatching` no-regression snapshots so the e2e suite passes on top of that fix. For end users this carries no behavioral change of its own — it only re-records the expected outputs of `fc.stringMatching`. Notably, the fix brings the generated values back to their correct form: the odd trailing `@.` artifacts that the earlier speedup had introduced are gone, so the two affected snapshots (`stringMatching` and `stringMatching({maxLength:10})` in `test/e2e/NoRegression.spec.ts`) revert to their pre-regression shape. No other no-regression snapshots changed, and `NoRegressionStack.spec.ts` was unaffected. Impact level: this is a test-only change (no library code), so it does not warrant a changeset of its own — it belongs with the perf PR it stacks on. Scope is a single concern: regenerating the no-regression snapshots invalidated by the stringMatching fix. Snapshots were produced via `vitest -u` and verified by re-running `test/e2e/NoRegression.spec.ts` (85 passing) and `test/e2e/NoRegressionStack.spec.ts` (6 passing). These snapshots would have failed against the fix without this update — that mismatch is exactly what this PR resolves. Fixes #issue-number <!-- Add any additional context here --> ## Checklist — _Don't delete this checklist and make sure you do the following before opening the PR_ - [ ] I have a full understanding of every line in this PR — whether the code was hand-written, AI-generated, copied from external sources or produced by any other tool - [ ] I flagged the impact of my change (minor / patch / major) either by running `pnpm run bump` or by following the instructions from the changeset bot - [ ] I kept this PR focused on a single concern and did not bundle unrelated changes - [ ] I followed the [gitmoji](https://gitmoji.dev/) specification for the name of the PR, including the package scope (e.g. `🐛(vitest) Something...`) when the change targets a package other than `fast-check` - [ ] I added relevant tests and they would have failed without my PR (when applicable) <!-- PRs not checking all the boxes may take longer before being reviewed --> <!-- More about contributing at https://github.com/dubzzz/fast-check/blob/main/CONTRIBUTING.md --> --- _Generated by [Claude Code](https://claude.ai/code/session_011nEBy7JcAAQ1nnYK1hvLhF)_ Co-authored-by: Claude <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The problem got detected by Claude on #7044 but the fix was really targeting a sub-part of the problem. This fix address a way larger range and thus make
fc.stringMatchingeven faster and in even more cases.The issues was that a regex such as
/^abc$/was resulting into a tuple of 5 constants: '', 'a', 'b', 'c', '' to be spawned on fast-check side. Actually it could have be summarized by just one 'abc'.This PR tries to merge together consecutive chars before creating and calling the constant arbitraries in the case of an Alternative regex node.
Our benchmarks gives us:
✓ fast-check test/bench/arbitraries.bench.ts > generate 8230ms name hz min max mean p75 p99 p995 p999 rme samples · stringMatching(/^abc$/) 1,867,398.80 0.0003 2.0225 0.0005 0.0006 0.0014 0.0019 0.0085 ±2.08% 933700 [5.32x] ⇑ stringMatching(/^abc$/) 351,266.59 0.0003 14.1048 0.0028 0.0008 0.0023 0.0026 0.0164 ±17.24% 175659 (baseline) · stringMatching(/^[a-zA-Z0-9]+$/) 591,376.41 0.0005 4.0245 0.0017 0.0020 0.0041 0.0046 0.0121 ±2.25% 295689 [6.24x] ⇑ stringMatching(/^[a-zA-Z0-9]+$/) 94,766.01 0.0006 16.3403 0.0106 0.0033 0.0060 0.0105 3.0316 ±19.38% 47655 (baseline) · stringMatching(/^\d+$/) 1,003,007.88 0.0004 0.3965 0.0010 0.0011 0.0022 0.0024 0.0089 ±0.55% 501504 [5.64x] ⇑ stringMatching(/^\d+$/) 177,850.39 0.0005 11.1158 0.0056 0.0020 0.0044 0.0053 1.4381 ±15.46% 89096 (baseline) · stringMatching(/^\w+$/) 1,020,510.99 0.0004 0.3775 0.0010 0.0011 0.0019 0.0022 0.0085 ±0.45% 510256 [3.51x] ⇑ stringMatching(/^\w+$/) 290,405.69 0.0004 6.3031 0.0034 0.0020 0.0032 0.0040 0.2449 ±10.40% 145312 (baseline) · stringMatching(/^[a-z]{3,10}$/) 667,954.99 0.0007 0.4847 0.0015 0.0017 0.0031 0.0036 0.0102 ±0.58% 333978 [3.49x] ⇑ stringMatching(/^[a-z]{3,10}$/) 191,603.56 0.0010 10.0363 0.0052 0.0028 0.0044 0.0051 0.1750 ±13.18% 95802 (baseline) · stringMatching(/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/) 230,503.22 0.0016 2.5397 0.0043 0.0047 0.0089 0.0117 0.0190 ±1.62% 115252 [2.30x] ⇑ stringMatching(/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/) 100,409.79 0.0020 21.8668 0.0100 0.0082 0.0168 0.0249 1.0359 ±10.18% 50205 (baseline) · stringMatching(/^(\d{4})-(\d{2})-(\d{2})$/) 526,714.67 0.0012 6.5534 0.0019 0.0018 0.0033 0.0036 0.0118 ±4.33% 263358 [1.82x] ⇑ stringMatching(/^(\d{4})-(\d{2})-(\d{2})$/) 288,950.59 0.0013 4.3007 0.0035 0.0030 0.0042 0.0049 0.0241 ±5.13% 145014 (baseline) · stringMatching(/^[+-]?\d+(\.\d+)?$/) 497,027.18 0.0007 0.4345 0.0020 0.0024 0.0049 0.0054 0.0130 ±0.59% 248515 [2.81x] ⇑ stringMatching(/^[+-]?\d+(\.\d+)?$/) 176,813.83 0.0008 9.7645 0.0057 0.0040 0.0081 0.0130 0.2357 ±11.77% 88407 (baseline) · stringMatching(/^(foo|bar|baz)$/) 1,463,213.15 0.0004 0.7321 0.0007 0.0007 0.0014 0.0016 0.0030 ±0.58% 731607 [2.60x] ⇑ stringMatching(/^(foo|bar|baz)$/) 562,689.57 0.0006 4.8751 0.0018 0.0013 0.0022 0.0027 0.0195 ±7.20% 281345 (baseline)Checklist
— Don't delete this checklist and make sure you do the following before opening the PR
pnpm run bumpor by following the instructions from the changeset bot🐛(vitest) Something...) when the change targets a package other thanfast-check