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 string builder #5243

Closed
wants to merge 1 commit into from
Closed

faster string builder #5243

wants to merge 1 commit into from

Conversation

dubzzz
Copy link
Owner

@dubzzz dubzzz commented Aug 26, 2024

Description

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: ...
  • Impacts: ...

Copy link

changeset-bot bot commented Aug 26, 2024

⚠️ No Changeset found

Latest commit: 014f110

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@dubzzz dubzzz added the 🧪 Experiment Performing some experiments for potential future features implying deep changes label Aug 26, 2024
Copy link

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 014f110:

Sandbox Source
@fast-check/examples Configuration

Copy link
Contributor

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

Copy link

codecov bot commented Aug 26, 2024

Codecov Report

Attention: Patch coverage is 88.00000% with 6 lines in your changes missing coverage. Please review.

Project coverage is 95.28%. Comparing base (4e04fda) to head (014f110).
Report is 116 commits behind head on main.

Files with missing lines Patch % Lines
packages/fast-check/src/utils/globals.ts 73.33% 4 Missing ⚠️
...ck/src/arbitrary/_internals/StringUnitArbitrary.ts 94.28% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5243      +/-   ##
==========================================
- Coverage   95.32%   95.28%   -0.04%     
==========================================
  Files         234      234              
  Lines       10414    10454      +40     
  Branches     2774     2789      +15     
==========================================
+ Hits         9927     9961      +34     
- Misses        487      493       +6     
Flag Coverage Δ
unit-tests 95.28% <88.00%> (-0.04%) ⬇️
unit-tests-18.x-Linux 95.28% <88.00%> (-0.04%) ⬇️
unit-tests-20.x-Linux 95.28% <88.00%> (-0.04%) ⬇️
unit-tests-22.x-Linux 95.28% <88.00%> (-0.04%) ⬇️
unit-tests-latest-Linux 95.28% <88.00%> (-0.04%) ⬇️

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
Copy link
Owner Author

dubzzz commented Aug 26, 2024

Quick stats from https://github.com/dubzzz/fast-check-benchmarks/actions/runs/10564220421/job/29266137622:

 │ 36      │ 'Property(fc.string()) on [email protected]'                                                                            │ '4,304'  │ 232288.18999661598 │ '±7.93%'  │ 100     │
│ 37      │ 'Property(fc.string()) on fast-check@main'                                                                              │ '4,572'  │ 218695.099997567   │ '±9.12%'  │ 100     │
│ 38      │ 'Property(fc.string()) on fast-check@extra'                                                                             │ '4,120'  │ 242704.4000022579  │ '±8.46%'  │ 100     │
│ 39      │ '—'                                                                                                                     │ '—'      │ '—'                │ '—'       │ '—'     │
│ 40      │ "Property(fc.string({ minLength: 0, maxLength: 500, size: 'max' })) on [email protected]"                               │ '361'    │ 2762602.10000386   │ '±2.11%'  │ 100     │
│ 41      │ "Property(fc.string({ minLength: 0, maxLength: 500, size: 'max' })) on fast-check@main"                                 │ '350'    │ 2855386.4800039446 │ '±3.40%'  │ 100     │
│ 42      │ "Property(fc.string({ minLength: 0, maxLength: 500, size: 'max' })) on fast-check@extra"                                │ '356'    │ 2806718.819999369  │ '±2.35%'  │ 100     │
│ 43      │ '—'                                                                                                                     │ '—'      │ '—'                │ '—'       │ '—'     │
│ 44      │ "Property(fc.string({ minLength: 0, maxLength: 25_000, size: 'max' })) on [email protected]"                            │ '5'      │ 180600766.5200025  │ '±2.53%'  │ 100     │
│ 45      │ "Property(fc.string({ minLength: 0, maxLength: 25_000, size: 'max' })) on fast-check@main"                              │ '5'      │ 179889561.0000007  │ '±2.63%'  │ 100     │
│ 46      │ "Property(fc.string({ minLength: 0, maxLength: 25_000, size: 'max' })) on fast-check@extra"                             │ '5'      │ 178884024.72000045 │ '±2.69%'  │ 100     │
│ 47      │ '—'                                                                                                                     │ '—'      │ '—'                │ '—'       │ '—'     │
│ 48      │ "Property(fc.string({ unit:'grapheme-composite' })) on [email protected]"                                               │ '1,713'  │ 583576.9199987408  │ '±7.69%'  │ 100     │
│ 49      │ "Property(fc.string({ unit:'grapheme-composite' })) on fast-check@main"                                                 │ '1,934'  │ 516992.73999780416 │ '±4.49%'  │ 100     │
│ 50      │ "Property(fc.string({ unit:'grapheme-composite' })) on fast-check@extra"                                                │ '4,029'  │ 248156.24000213575 │ '±6.82%'  │ 100     │
│ 51      │ '—'                                                                                                                     │ '—'      │ '—'                │ '—'       │ '—'     │
│ 52      │ "Property(fc.string({ unit:'grapheme-composite', minLength: 0, maxLength: 500, size: 'max' })) on [email protected]"    │ '60'     │ 16404330.040003989 │ '±1.82%'  │ 100     │
│ 53      │ "Property(fc.string({ unit:'grapheme-composite', minLength: 0, maxLength: 500, size: 'max' })) on fast-check@main"      │ '61'     │ 16215262.000004295 │ '±1.58%'  │ 100     │
│ 54      │ "Property(fc.string({ unit:'grapheme-composite', minLength: 0, maxLength: 500, size: 'max' })) on fast-check@extra"     │ '299'    │ 3341904.8900000053 │ '±2.57%'  │ 100     │
│ 55      │ '—'                                                                                                                     │ '—'      │ '—'                │ '—'       │ '—'     │
│ 56      │ "Property(fc.string({ unit:'grapheme-composite', minLength: 0, maxLength: 25_000, size: 'max' })) on [email protected]" │ '1'      │ 872918943.4099983  │ '±1.64%'  │ 100     │
│ 57      │ "Property(fc.string({ unit:'grapheme-composite', minLength: 0, maxLength: 25_000, size: 'max' })) on fast-check@main"   │ '1'      │ 875319785.1599997  │ '±1.62%'  │ 100     │
│ 58      │ "Property(fc.string({ unit:'grapheme-composite', minLength: 0, maxLength: 25_000, size: 'max' })) on fast-check@extra"  │ '4'      │ 219242737.48000735 │ '±2.37%'  │ 100     │
│ 59      │ '—'                                                                                                                     │ '—'      │ '—'                │ '—'       │ '—'     │
│ 60      │ "Property(fc.string({ unit:'grapheme' })) on [email protected]"                                                         │ '1,487'  │ 672319.1400012001  │ '±11.26%' │ 100     │
│ 61      │ "Property(fc.string({ unit:'grapheme' })) on fast-check@main"                                                           │ '1,699'  │ 588359.929996077   │ '±7.26%'  │ 100     │
│ 62      │ "Property(fc.string({ unit:'grapheme' })) on fast-check@extra"                                                          │ '3,713'  │ 269276.8099962268  │ '±11.53%' │ 100     │
│ 63      │ '—'                                                                                                                     │ '—'      │ '—'                │ '—'       │ '—'     │
│ 64      │ "Property(fc.string({ unit:'grapheme', minLength: 0, maxLength: 500, size: 'max' })) on [email protected]"              │ '58'     │ 17055338.280001886 │ '±1.37%'  │ 100     │
│ 65      │ "Property(fc.string({ unit:'grapheme', minLength: 0, maxLength: 500, size: 'max' })) on fast-check@main"                │ '58'     │ 17030465.200002074 │ '±1.75%'  │ 100     │
│ 66      │ "Property(fc.string({ unit:'grapheme', minLength: 0, maxLength: 500, size: 'max' })) on fast-check@extra"               │ '299'    │ 3340003.819995327  │ '±2.51%'  │ 100     │
│ 67      │ '—'                                                                                                                     │ '—'      │ '—'                │ '—'       │ '—'     │
│ 68      │ "Property(fc.string({ unit:'grapheme', minLength: 0, maxLength: 25_000, size: 'max' })) on [email protected]"           │ '1'      │ 906985892.3500043  │ '±1.56%'  │ 100     │
│ 69      │ "Property(fc.string({ unit:'grapheme', minLength: 0, maxLength: 25_000, size: 'max' })) on fast-check@main"             │ '1'      │ 909319767.740001   │ '±1.53%'  │ 100     │
│ 70      │ "Property(fc.string({ unit:'grapheme', minLength: 0, maxLength: 25_000, size: 'max' })) on fast-check@extra"            │ '4'      │ 216915173.79000086 │ '±2.12%'  │ 100     │

@dubzzz dubzzz closed this Oct 30, 2024
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 -->

The arbitrary `mapToConstant` used to rely on a linear scan to get the
entry to be used to generate the element. It used to be sub-optimal for
cases implying several entries (a normal scenario for this arbitrary).

Our new implementation relies on a dichotomic-lookup that will be way
less costly to execute.

This change should have a visible impact when generating strings using
the `string` arbitrary.

Supersede #5243

<!-- * 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 `mapToConstant` but also any arbitrary derived
from it: `string` and many others

<!-- [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
🧪 Experiment Performing some experiments for potential future features implying deep changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant