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 instantiation of internet-related arbitraries #5402

Merged
merged 1 commit into from
Nov 2, 2024

Conversation

dubzzz
Copy link
Owner

@dubzzz dubzzz commented Nov 2, 2024

Description

These arbitraries used to be relatively costly to instantiate and re-instantiate. While generally not a huge concern, when used in multiple properties and arbitraries this small cost (around 10ms measured for some of them) could be considered as far too much.

Tis PR is responsible to drop this time for later re-instantiations of the same internet-related arbitrary (and also other internet-related arbitraries).

The measured perfomance uplift is impressive:

┌──────────────────────────────────────────────────────────────────┬─────────────┬────────────────────┬────────────┬─────────┐
│ Task Name                                                        │ ops/sec     │ Average Time (ns)  │ Margin     │ Samples │
├──────────────────────────────────────────────────────────────────┼─────────────┼────────────────────┼────────────┼─────────┤
│ 'emailAddress [property] on [email protected]'                   │ '91'        │ 10889826.509999111 │ '±1.25%'   │ 100     │
│ 'emailAddress [property] on fast-check@main'                     │ '92'        │ 10844747.599998374 │ '±0.96%'   │ 100     │
│ 'emailAddress [property] on fast-check@extra'                    │ '767'       │ 1303581.2200023793 │ '±4.36%'   │ 100     │
│ '—'                                                              │ '—'         │ '—'                │ '—'        │ '—'     │
│ 'webUrl [property] on [email protected]'                         │ '184'       │ 5407323.470002157  │ '±1.87%'   │ 100     │
│ 'webUrl [property] on fast-check@main'                           │ '186'       │ 5375564.689997118  │ '±1.65%'   │ 100     │
│ 'webUrl [property] on fast-check@extra'                          │ '1,309'     │ 763888.6699988507  │ '±5.65%'   │ 100     │
│ '—'                                                              │ '—'         │ '—'                │ '—'        │ '—'     │
│ 'domain [property] on [email protected]'                         │ '177'       │ 5625156.560001778  │ '±1.35%'   │ 100     │
│ 'domain [property] on fast-check@main'                           │ '176'       │ 5655945.269999793  │ '±1.44%'   │ 100     │
│ 'domain [property] on fast-check@extra'                          │ '2,158'     │ 463293.92999759875 │ '±8.30%'   │ 100     │
│ '—'                                                              │ '—'         │ '—'                │ '—'        │ '—'     │
│ 'webPath [property] on [email protected]'                        │ '2,654'     │ 376671.95000103675 │ '±11.80%'  │ 100     │
│ 'webPath [property] on fast-check@main'                          │ '2,710'     │ 368881.23999524396 │ '±11.18%'  │ 100     │
│ 'webPath [property] on fast-check@extra'                         │ '3,553'     │ 281420.0099988375  │ '±8.83%'   │ 100     │
│ '—'                                                              │ '—'         │ '—'                │ '—'        │ '—'     │
│ '—'                                                              │ '—'         │ '—'                │ '—'        │ '—'     │
│ 'emailAddress [init] on [email protected]'                       │ '102'       │ 9717271.019999754  │ '±0.93%'   │ 100     │
│ 'emailAddress [init] on fast-check@main'                         │ '102'       │ 9727080.830000922  │ '±0.90%'   │ 100     │
│ 'emailAddress [init] on fast-check@extra'                        │ '208,495'   │ 4796.270001097582  │ '±30.89%'  │ 100     │
│ '—'                                                              │ '—'         │ '—'                │ '—'        │ '—'     │
│ 'webUrl [init] on [email protected]'                             │ '203'       │ 4915872.42000096   │ '±5.11%'   │ 100     │
│ 'webUrl [init] on fast-check@main'                               │ '224'       │ 4459312.690000515  │ '±1.53%'   │ 100     │
│ 'webUrl [init] on fast-check@extra'                              │ '129,025'   │ 7750.43000059668   │ '±28.60%'  │ 100     │
│ '—'                                                              │ '—'         │ '—'                │ '—'        │ '—'     │
│ 'domain [init] on [email protected]'                             │ '193'       │ 5162941.229996504  │ '±1.27%'   │ 100     │
│ 'domain [init] on fast-check@main'                               │ '194'       │ 5151196.849999833  │ '±1.27%'   │ 100     │
│ 'domain [init] on fast-check@extra'                              │ '311,647'   │ 3208.749998593703  │ '±35.53%'  │ 100     │
│ '—'                                                              │ '—'         │ '—'                │ '—'        │ '—'     │
│ 'webPath [init] on [email protected]'                            │ '11,708'    │ 85407.009999617    │ '±34.85%'  │ 100     │
│ 'webPath [init] on fast-check@main'                              │ '14,022'    │ 71313.10000200756  │ '±29.80%'  │ 100     │
│ 'webPath [init] on fast-check@extra'                             │ '319,764'   │ 3127.3000017972663 │ '±35.54%'  │ 100     │
└──────────────────────────────────────────────────────────────────┴─────────────┴────────────────────┴────────────┴─────────┘

The initialization time (means second initialization of the arbitrary and later) decreased by a significant factor: from 200 per second to 130k per second for webUrl. This huge improvement also drove significant performance improvements on properties running against such arbitraries by moving from 180 executions per seconds to 1300 (with executions meaning full property execution and thus 100 runs of the predicate).

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 internet related arbitraries at instantiation time

These arbitraries used to be relatively costly to instantiate and re-instantiate. While generally not a huge concern, when used in multiple properties and arbitraries this small cost (around 10ms measured for some of them) could be considered as far too much.

Tis PR is responsible to drop this time for later re-instantiations of the same internet-related arbitrary (and also other internet-related aribitraries).
Copy link

pkg-pr-new bot commented Nov 2, 2024

Open in Stackblitz@fast-check/examples

@fast-check/ava

yarn add https://pkg.pr.new/@fast-check/[email protected]

@fast-check/expect-type

yarn add https://pkg.pr.new/@fast-check/[email protected]

fast-check

yarn add https://pkg.pr.new/[email protected]

@fast-check/jest

yarn add https://pkg.pr.new/@fast-check/[email protected]

@fast-check/packaged

yarn add https://pkg.pr.new/@fast-check/[email protected]

@fast-check/poisoning

yarn add https://pkg.pr.new/@fast-check/[email protected]

@fast-check/vitest

yarn add https://pkg.pr.new/@fast-check/[email protected]

@fast-check/worker

yarn add https://pkg.pr.new/@fast-check/[email protected]

commit: 281ca69

Copy link
Contributor

github-actions bot commented Nov 2, 2024

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

Copy link

codecov bot commented Nov 2, 2024

Codecov Report

Attention: Patch coverage is 91.39785% with 8 lines in your changes missing coverage. Please review.

Project coverage is 95.19%. Comparing base (e728907) to head (281ca69).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
packages/fast-check/src/utils/globals.ts 71.42% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5402      +/-   ##
==========================================
- Coverage   95.24%   95.19%   -0.05%     
==========================================
  Files         235      235              
  Lines       10583    10644      +61     
  Branches     2826     2839      +13     
==========================================
+ Hits        10080    10133      +53     
- Misses        503      511       +8     
Flag Coverage Δ
unit-tests 95.19% <91.39%> (-0.05%) ⬇️
unit-tests-18.x-Linux 95.19% <91.39%> (-0.05%) ⬇️
unit-tests-20.x-Linux 95.19% <91.39%> (-0.05%) ⬇️
unit-tests-22.x-Linux 95.19% <91.39%> (-0.05%) ⬇️
unit-tests-latest-Linux 95.19% <91.39%> (-0.05%) ⬇️

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 140e3ab into main Nov 2, 2024
72 of 74 checks passed
@dubzzz dubzzz deleted the faster-internet branch November 2, 2024 22:48
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