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

feat: add flushPromises and peekPromiseState then deprecate promiseState #38

Merged
merged 7 commits into from
Aug 21, 2024

Conversation

lambdalisue
Copy link
Member

@lambdalisue lambdalisue commented Aug 19, 2024

Close #37

Note that the behavior is different so we cannot simply compare the performance but if users don't need to wait internal microtask queue, peekPromiseState is approx. 3,000 times faster than promiseState

file:///Users/alisue/ogh/jsr-core/asyncutil/peek_promise_state_bench.ts
benchmark      time (avg)        iter/s             (min … max)       p75       p99      p995
--------------------------------------------------------------- -----------------------------

group peekPromiseState (fulfilled)
current        309.9 ns/iter   3,226,890.9 (293.85 ns … 421.18 ns) 307.97 ns 397.7 ns 421.18 ns

group peekPromiseState (rejected)
current       428.95 ns/iter   2,331,284.6 (420.77 ns … 526.07 ns) 427.32 ns 518.06 ns 526.07 ns

group peekPromiseState (pending)
current       257.49 ns/iter   3,883,658.2 (251.18 ns … 285.46 ns) 258.1 ns 275.92 ns 277.24 ns


file:///Users/alisue/ogh/jsr-core/asyncutil/promise_state_bench.ts
benchmark      time (avg)        iter/s             (min … max)       p75       p99      p995
--------------------------------------------------------------- -----------------------------

group promiseState (fulfilled)
current         1.24 ms/iter         804.3    (20.67 µs … 5.48 ms) 1.19 ms 3.39 ms 4.79 ms

group promiseState (rejected)
current         1.32 ms/iter         760.1    (14.42 µs … 10.1 ms) 1.22 ms 5 ms 6.19 ms

group promiseState (pending)
current         1.31 ms/iter         762.0    (23.12 µs … 8.24 ms) 1.22 ms 4.05 ms 6.34 ms

@lambdalisue lambdalisue marked this pull request as draft August 19, 2024 19:12
@lambdalisue lambdalisue force-pushed the improve-promise-state branch from 3c20553 to 9b7ecd0 Compare August 20, 2024 04:17
@lambdalisue lambdalisue changed the title feat: Improve performance of promiseState (WIP) feat(promiseState): add immediate option to skip internal handling that waits for promises Aug 20, 2024
@lambdalisue lambdalisue marked this pull request as ready for review August 20, 2024 04:18
Copy link

codecov bot commented Aug 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.10%. Comparing base (5950811) to head (45c948e).
Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #38      +/-   ##
==========================================
+ Coverage   93.00%   93.10%   +0.10%     
==========================================
  Files          14       16       +2     
  Lines         400      406       +6     
  Branches       38       38              
==========================================
+ Hits          372      378       +6     
  Misses         28       28              

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

@lambdalisue lambdalisue force-pushed the improve-promise-state branch from 9b7ecd0 to 9ec7a6d Compare August 20, 2024 15:10
@lambdalisue lambdalisue changed the title feat(promiseState): add immediate option to skip internal handling that waits for promises feat: add flushPromises and peekPromiseState then deprecate promiseState Aug 20, 2024
In favor of `peekPromiseState` and `flushPromises`.

```ts
import { flushPromises } from "@core/asyncutil/flush-promises.ts";
import { peekPromiseState } from "@core/asyncutil/peek-promise-state";

const p = Promise.resolve(1)
  .then(() => 2)
  .then(() => 3);

await flushPromises();
console.log(await peekPromiseState(p)); // "fulfilled"
```
`promiseState` becomes deprecated so we use `peekPromiseState` with
`flushPromises` instead.
@lambdalisue lambdalisue force-pushed the improve-promise-state branch from 9ec7a6d to 45c948e Compare August 21, 2024 03:38
@lambdalisue lambdalisue merged commit f5a9505 into main Aug 21, 2024
6 checks passed
@lambdalisue lambdalisue deleted the improve-promise-state branch August 21, 2024 03:50
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.

perfomance: promiseState optimization
1 participant