Skip to content
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

Merged
merged 2 commits into from
Oct 31, 2024

Conversation

dubzzz
Copy link
Owner

@dubzzz dubzzz commented Oct 31, 2024

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.

ChecklistDon't delete this checklist and make sure you do the following before opening the PR

  • The name of my PR follows gitmoji specification
  • My PR references one of several related issues (if any)
    • New features or breaking changes must come with an associated Issue or Discussion
    • My PR does not add any new dependency without an associated Issue or Discussion
  • My PR includes bumps details, please run yarn bump and flag the impacts properly
  • My PR adds relevant tests and they would have failed without my PR (when applicable)

Advanced

  • Category: ⚡️ Improve performance
  • Impacts: Faster init of string arbitrary

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.
Copy link

changeset-bot bot commented Oct 31, 2024

🦋 Changeset detected

Latest commit: c0e55aa

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
fast-check Minor

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

Copy link

codesandbox-ci bot commented Oct 31, 2024

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:

Sandbox Source
@fast-check/examples Configuration

Copy link
Contributor

👋 A preview of the new documentation is available at: http://6723f4efbcb45d3d4a2132c4--dubzzz-fast-check.netlify.app

@dubzzz
Copy link
Owner Author

dubzzz commented Oct 31, 2024

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

Copy link
Contributor

👋 A preview of the new documentation is available at: http://6723f68b8243cc4ad8fea50e--dubzzz-fast-check.netlify.app

Copy link

codecov bot commented Oct 31, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.29%. Comparing base (d336e2e) to head (c0e55aa).
Report is 1 commits behind head on main.

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           
Flag Coverage Δ
unit-tests 95.29% <100.00%> (+<0.01%) ⬆️
unit-tests-18.x-Linux 95.29% <100.00%> (+<0.01%) ⬆️
unit-tests-20.x-Linux 95.29% <100.00%> (+<0.01%) ⬆️
unit-tests-22.x-Linux 95.29% <100.00%> (+<0.01%) ⬆️
unit-tests-latest-Linux 95.29% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dubzzz dubzzz merged commit 16377a8 into main Oct 31, 2024
73 checks passed
@dubzzz dubzzz deleted the faster-init-string branch October 31, 2024 21:41
dubzzz added a commit that referenced this pull request Oct 31, 2024
**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?
-->
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.

1 participant