-
-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
⚡️ Faster initialization of string
with faster slices
#5388
Conversation
When initializing the `string` arbitrary, we first check what are the known-to-be-vulnerable-strings that we could possibly generate for this instance. As such we need to take any known-to-be-vulnerable-string and check if it could have been generated by the string builder we are planning to build. This operation is pretty costly as it implies a backtracking algorithm possibly failing and retrying multiple times. The change introduced by this PR reduces the overhead linked to this computation by dropping part of the operations that were done twice.
🦋 Changeset detectedLatest commit: c0e55aa 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 |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit c0e55aa:
|
👋 A preview of the new documentation is available at: http://6723f4efbcb45d3d4a2132c4--dubzzz-fast-check.netlify.app |
Benchmark results: ┌───────────────────────────────────────────────────────────────────────┬──────────┬────────────────────┬───────────┬─────────┐
│ Task Name | ops/sec │ Average Time (ns) │ Margin │ Samples │
├───────────────────────────────────────────────────────────────────────┼──────────┼────────────────────┼───────────┼─────────┤
│ fc.char() on 3.21.0 | '9,483' │ 105442.27000093088 │ '±6.09%' │ 100 │
│ fc.char() on 3.22.0 | '9,783' │ 102209.54999967944 │ '±7.89%' │ 100 │
│ fc.char() on main | '9,426' │ 106085.99999861326 │ '±8.16%' │ 100 │
│ fc.char() on extra | '9,242' │ 108198.2799974503 │ '±7.65%' │ 100 │
│ '—' | '—' │ '—' │ '—' │ '—' │
│ fc.string() on 3.21.0 | '4,448' │ 224784.87999527715 │ '±6.96%' │ 100 │
│ fc.string() on 3.22.0 | '4,149' │ 240980.42999976315 │ '±8.54%' │ 100 │
│ fc.string() on main | '4,080' │ 245093.46999344416 │ '±7.47%' │ 100 │
│ fc.string() on extra | '4,406' │ 226920.5400015926 │ '±7.04%' │ 100 │
│ '—' | '—' │ '—' │ '—' │ '—' │
│ fc.constant('').chain(() => fc.string()) on 3.21.0 | '870' │ 1148594.2100029206 │ '±15.48%' │ 100 │
│ fc.constant('').chain(() => fc.string()) on 3.22.0 | '297' │ 3363599.1300002206 │ '±3.48%' │ 100 │
│ fc.constant('').chain(() => fc.string()) on main | '253' │ 3945451.5499959234 │ '±14.75%' │ 100 │
│ fc.constant('').chain(() => fc.string()) on extra | '299' │ 3340826.710004476 │ '±3.45%' │ 100 │
│ '—' | '—' │ '—' │ '—' │ '—' │
│ fc.string({ minLength: 0, maxLength: 500, size: 'max' }) on 3.21.0 | '347' │ 2880982.699994929 │ '±1.98%' │ 100 │
│ fc.string({ minLength: 0, maxLength: 500, size: 'max' }) on 3.22.0 | '312' │ 3202521.8100025086 │ '±2.69%' │ 100 │
│ fc.string({ minLength: 0, maxLength: 500, size: 'max' }) on main | '230' │ 4344063.030000543 │ '±1.92%' │ 100 │
│ fc.string({ minLength: 0, maxLength: 500, size: 'max' }) on extra | '263' │ 3801751.36000209 │ '±2.14%' │ 100 │
│ '—' | '—' │ '—' │ '—' │ '—' │
│ fc.string({ minLength: 0, maxLength: 25_000, size: 'max' }) on 3.21.0 | '4' │ 214892315.8600001 │ '±2.23%' │ 100 │
│ fc.string({ minLength: 0, maxLength: 25_000, size: 'max' }) on 3.22.0 | '4' │ 244858172.7299979 │ '±1.79%' │ 100 │
│ fc.string({ minLength: 0, maxLength: 25_000, size: 'max' }) on main | '3' │ 257753839.28000173 │ '±2.19%' │ 100 │
│ fc.string({ minLength: 0, maxLength: 25_000, size: 'max' }) on extra | '4' │ 230971961.04000148 │ '±2.06%' │ 100 │
└───────────────────────────────────────────────────────────────────────┴──────────┴────────────────────┴───────────┴─────────┘ More details at: https://github.com/dubzzz/fast-check-benchmarks/actions/runs/11620131878 |
👋 A preview of the new documentation is available at: http://6723f68b8243cc4ad8fea50e--dubzzz-fast-check.netlify.app |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #5388 +/- ##
=======================================
Coverage 95.28% 95.29%
=======================================
Files 235 235
Lines 10504 10519 +15
Branches 2801 2804 +3
=======================================
+ Hits 10009 10024 +15
Misses 495 495
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
**Description** <!-- Please provide a short description and potentially linked issues justifying the need for this PR --> Follow-up of #5388 <!-- * Your PR is fixing a bug or regression? Check for existing issues related to this bug and link them --> <!-- * Your PR is adding a new feature? Make sure there is a related issue or discussion attached to it --> <!-- You can provide any additional context to help into understanding what's this PR is attempting to solve: reproduction of a bug, code snippets... --> **Checklist** — _Don't delete this checklist and make sure you do the following before opening the PR_ - [x] The name of my PR follows [gitmoji](https://gitmoji.dev/) specification - [x] My PR references one of several related issues (if any) - [x] New features or breaking changes must come with an associated Issue or Discussion - [x] My PR does not add any new dependency without an associated Issue or Discussion - [x] My PR includes bumps details, please run `yarn bump` and flag the impacts properly - [x] My PR adds relevant tests and they would have failed without my PR (when applicable) <!-- More about contributing at https://github.com/dubzzz/fast-check/blob/main/CONTRIBUTING.md --> **Advanced** <!-- How to fill the advanced section is detailed below! --> - [x] Category: ⚡️ Improve performance - [x] Impacts: Faster init of `string` arbitrary <!-- [Category] Please use one of the categories below, it will help us into better understanding the urgency of the PR --> <!-- * ✨ Introduce new features --> <!-- * 📝 Add or update documentation --> <!-- * ✅ Add or update tests --> <!-- * 🐛 Fix a bug --> <!-- * 🏷️ Add or update types --> <!-- * ⚡️ Improve performance --> <!-- * _Other(s):_ ... --> <!-- [Impacts] Please provide a comma separated list of the potential impacts that might be introduced by this change --> <!-- * Generated values: Can your change impact any of the existing generators in terms of generated values, if so which ones? when? --> <!-- * Shrink values: Can your change impact any of the existing generators in terms of shrink values, if so which ones? when? --> <!-- * Performance: Can it require some typings changes on user side? Please give more details --> <!-- * Typings: Is there a potential performance impact? In which cases? -->
Description
When initializing the
string
arbitrary, we first check what are the known-to-be-vulnerable-strings that we could possibly generate for this instance.As such we need to take any known-to-be-vulnerable-string and check if it could have been generated by the string builder we are planning to build. This operation is pretty costly as it implies a backtracking algorithm possibly failing and retrying multiple times.
The change introduced by this PR reduces the overhead linked to this computation by dropping part of the operations that were done twice.
Checklist — Don't delete this checklist and make sure you do the following before opening the PR
yarn bump
and flag the impacts properlyAdvanced