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: performance fix #34

Merged
merged 12 commits into from
Aug 19, 2024
Merged

feat: performance fix #34

merged 12 commits into from
Aug 19, 2024

Conversation

lambdalisue
Copy link
Member

@lambdalisue lambdalisue commented Aug 16, 2024

Continue from #31

cpu: Apple M1 Max
runtime: deno 1.45.5 (aarch64-apple-darwin)

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

group Barrier#wait
current                    184.58 µs/iter       5,417.8                            (165.38 µs … 517.5 µs)              173.17 µs              419.12 µs              431.88 µs
v1.0.0                     248.35 µs/iter       4,026.5                              (205 µs … 565.21 µs)                 229 µs              510.62 µs              517.75 µs

summary
  current
   1.35x faster than v1.0.0


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

group Lock#lock
current                    238.51 µs/iter       4,192.6                           (211.46 µs … 549.62 µs)              225.79 µs              496.46 µs               507.5 µs
v1.0.0                       52.9 ms/iter          18.9                             (47.09 ms … 56.71 ms)               55.55 ms               56.71 ms               56.71 ms

summary
  current
   221.8x faster than v1.0.0


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

group Mutex#wait
current                    414.06 µs/iter       2,415.1                              (366.67 µs … 2.8 ms)              384.33 µs              757.71 µs                1.65 ms
v1.0.0                      52.04 ms/iter          19.2                             (46.98 ms … 56.89 ms)               54.69 ms               56.89 ms               56.89 ms

summary
  current
   125.68x faster than v1.0.0


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

group Notify#notifyAll
current                     296.2 µs/iter       3,376.1                            (252.5 µs … 730.54 µs)              269.75 µs              603.04 µs              611.88 µs
v1.0.0                     230.36 µs/iter       4,341.1                           (199.62 µs … 548.25 µs)              223.17 µs              409.88 µs              417.46 µs

summary
  current
   1.29x slower than v1.0.0

group Notify#notify
current                     406.6 µs/iter       2,459.4                           (345.54 µs … 831.54 µs)              379.38 µs              763.67 µs              790.67 µs
v1.0.0                      22.33 ms/iter          44.8                             (21.08 ms … 37.03 ms)               22.09 ms               37.03 ms               37.03 ms

summary
  current
   54.92x faster than v1.0.0


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

group Queue#push/pop
current                     154.2 µs/iter       6,485.2                           (146.21 µs … 329.67 µs)              151.42 µs              263.92 µs              275.79 µs
v1.0.0                       1.13 ms/iter         881.3                             (919.08 µs … 5.15 ms)                1.01 ms                3.97 ms                4.73 ms

summary
  current
   7.36x faster than v1.0.0


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

group RwLock#lock
current                    271.94 µs/iter       3,677.2                              (247.58 µs … 689 µs)              258.33 µs              519.33 µs              540.79 µs
v1.0.0                      54.55 ms/iter          18.3                             (49.02 ms … 61.45 ms)               56.62 ms               61.45 ms               61.45 ms

summary
  current
   200.59x faster than v1.0.0

group RwLock#rlock
current                    206.41 µs/iter       4,844.7                           (182.83 µs … 558.88 µs)              196.38 µs              457.38 µs              478.71 µs
v1.0.0                      55.64 ms/iter          18.0                             (50.13 ms … 62.36 ms)               57.77 ms               62.36 ms               62.36 ms

summary
  current
   269.58x faster than v1.0.0


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

group Semaphore#lock
current                    231.89 µs/iter       4,312.4                           (207.62 µs … 547.54 µs)              215.67 µs              485.46 µs              500.75 µs
v1.0.0                      21.67 ms/iter          46.2                             (20.63 ms … 24.15 ms)               21.93 ms               24.15 ms               24.15 ms

summary
  current
   93.43x faster than v1.0.0


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

group Stack#push/pop
current                     111.6 µs/iter       8,960.5                           (100.17 µs … 497.96 µs)              110.21 µs              215.75 µs              223.58 µs
v1.0.0                       1.11 ms/iter         903.9                             (882.92 µs … 6.59 ms)                 996 µs                3.56 ms                4.91 ms

summary
  current
   9.91x faster than v1.0.0


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

group WaitGroup#wait
current                     64.17 µs/iter      15,583.6                             (59.5 µs … 209.42 µs)               66.88 µs               79.04 µs               92.62 µs
v1.0.0                      64.23 µs/iter      15,568.3                             (59.5 µs … 311.67 µs)               67.08 µs               78.92 µs                88.5 µs

summary
  current
   1x faster than v1.0.0

@lambdalisue lambdalisue force-pushed the performance-fix branch 3 times, most recently from 02617d0 to 14272f6 Compare August 16, 2024 21:22
@lambdalisue lambdalisue added the enhancement New feature or request label Aug 16, 2024
It seems `using` in Node is not as performant as expected.
Note that the performance in Deno seems not to be affected by this
change.

  benchmark      time (avg)        iter/s             (min … max)       p75       p99      p995
  --------------------------------------------------------------- -----------------------------

  group Lock#lock
  v1.0.0         52.84 ms/iter          18.9   (45.86 ms … 57.58 ms) 55.68 ms 57.58 ms 57.58 ms
  main           53.55 ms/iter          18.7   (47.32 ms … 73.59 ms) 55.52 ms 73.59 ms 73.59 ms

  summary
    v1.0.0
    1.01x faster than main

See #31 for detail
  benchmark      time (avg)        iter/s             (min … max)       p75       p99      p995
  --------------------------------------------------------------- -----------------------------

  group Semaphore#lock
  current       231.08 µs/iter       4,327.5    (207 µs … 565.42 µs) 214.17 µs 491.58 µs 503.88 µs
  v1.0.0         21.07 ms/iter          47.5   (20.46 ms … 23.17 ms) 21.06 ms 23.17 ms 23.17 ms

  summary
    current
    91.18x faster than v1.0.0
  benchmark      time (avg)        iter/s             (min … max)       p75       p99      p995
  --------------------------------------------------------------- -----------------------------

  group Mutex#wait
  current       395.68 µs/iter       2,527.3   (361.25 µs … 1.31 ms) 374.62 µs 716.46 µs 733.62 µs
  v1.0.0         52.76 ms/iter          19.0   (46.67 ms … 56.59 ms) 55.51 ms 56.59 ms 56.59 ms

  summary
    current
    133.33x faster than v1.0.0
  benchmark      time (avg)        iter/s             (min … max)       p75       p99      p995
  --------------------------------------------------------------- -----------------------------

  group Lock#lock
  current       231.74 µs/iter       4,315.2 (206.46 µs … 700.42 µs) 215.5 µs 488.58 µs 505.96 µs
  v1.0.0         52.28 ms/iter          19.1   (47.25 ms … 55.24 ms) 54.78 ms 55.24 ms 55.24 ms

  summary
    current
    225.59x faster than v1.0.0
  benchmark      time (avg)        iter/s             (min … max)       p75       p99      p995
  --------------------------------------------------------------- -----------------------------

  group RwLock#lock
  current       270.64 µs/iter       3,695.0 (247.21 µs … 681.58 µs) 257.83 µs 508.83 µs 532.21 µs
  v1.0.0         52.87 ms/iter          18.9   (47.98 ms … 57.47 ms) 55.87 ms 57.47 ms 57.47 ms

  summary
    current
    195.35x faster than v1.0.0

  group RwLock#rlock
  current       201.44 µs/iter       4,964.4   (182.46 µs … 1.18 ms) 189.58 µs 445.92 µs 474.75 µs
  v1.0.0         57.84 ms/iter          17.3   (52.11 ms … 78.27 ms) 59.24 ms 78.27 ms 78.27 ms

  summary
    current
    287.13x faster than v1.0.0
  benchmark      time (avg)        iter/s             (min … max)       p75       p99      p995
  --------------------------------------------------------------- -----------------------------

  group Barrier#wait
  current        61.42 µs/iter      16,280.8  (56.54 µs … 270.25 µs) 61.75 µs 129.17 µs 137.71 µs
  v1.0.0        251.46 µs/iter       3,976.7 (206.38 µs … 577.12 µs) 232.12 µs 518.33 µs 528.71 µs

  summary
    current
    4.09x faster than v1.0.0
  benchmark      time (avg)        iter/s             (min … max)       p75       p99      p995
  --------------------------------------------------------------- -----------------------------

  group Notify#notifyAll
  current       293.47 µs/iter       3,407.5 (251.46 µs … 676.88 µs) 266.04 µs 592.96 µs 608.17 µs
  v1.0.0        223.93 µs/iter       4,465.6 (200.75 µs … 452.79 µs) 215.67 µs 356.75 µs 370.08 µs

  summary
    current
    1.31x slower than v1.0.0

  group Notify#notify
  current       395.51 µs/iter       2,528.4 (344.42 µs … 953.71 µs) 365.83 µs 700.67 µs 717.75 µs
  v1.0.0         21.54 ms/iter          46.4   (20.82 ms … 23.01 ms) 21.89 ms 23.01 ms 23.01 ms

  summary
    current
    54.46x faster than v1.0.0
  benchmark      time (avg)        iter/s             (min … max)       p75       p99      p995
  --------------------------------------------------------------- -----------------------------

  group Queue#push/pop
  current       154.58 µs/iter       6,469.2    (146 µs … 425.71 µs) 151.83 µs 272.96 µs 297.25 µs
  v1.0.0           1.1 ms/iter         909.4   (917.17 µs … 5.96 ms) 993.5 µs 3.44 ms 3.58 ms

  summary
    current
    7.11x faster than v1.0.0
  benchmark      time (avg)        iter/s             (min … max)       p75       p99      p995
  --------------------------------------------------------------- -----------------------------

  group Stack#push/pop
  current       112.37 µs/iter       8,898.9 (100.12 µs … 348.71 µs) 111.25 µs 217.75 µs 225.96 µs
  v1.0.0          1.07 ms/iter         938.4   (882.54 µs … 3.94 ms) 969.21 µs 3.35 ms 3.55 ms

  summary
    current
    9.48x faster than v1.0.0
Copy link

codecov bot commented Aug 17, 2024

Codecov Report

Attention: Patch coverage is 96.47887% with 5 lines in your changes missing coverage. Please review.

Project coverage is 92.91%. Comparing base (227e7e5) to head (2ce4940).
Report is 13 commits behind head on main.

Files Patch % Lines
lock.ts 88.88% 1 Missing ⚠️
mutex.ts 85.71% 1 Missing ⚠️
queue.ts 88.88% 1 Missing ⚠️
semaphore.ts 83.33% 1 Missing ⚠️
stack.ts 88.88% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #34      +/-   ##
==========================================
+ Coverage   92.11%   92.91%   +0.79%     
==========================================
  Files          12       13       +1     
  Lines         355      395      +40     
  Branches       41       37       -4     
==========================================
+ Hits          327      367      +40     
  Misses         28       28              

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

@lambdalisue lambdalisue merged commit d397736 into main Aug 19, 2024
6 checks passed
@lambdalisue lambdalisue deleted the performance-fix branch August 19, 2024 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant