tildeio/rsvp.js — pull request #246 by stefanpenner (2014-05-15 02:00:55+00:00)
Title: More opts

more perf & refactoring

- reduce closures
- isolate necessary de-optimizations to small functions
- reduce overhead of internals usage by adding the ability for
_internals_ to subscribe to other promises without the expense of
`then`
- fulfillment with no subscribers need not attempt to queue and
broadcast to subscribers. The Act of subscribing queues, schedules and
flushes the micro task queue.

Still lots more low hanging fruit just need to find time.

MicroBenchmarks:

37.0.1991.0 canary
platform == build in promises

Running Benchmark Suite for test - All 1 ...
- [All 1] platform x 67,082 ops/sec ±3.62% (55 runs sampled)
- [All 1] rsvp-2.0.4 x 21,294 ops/sec ±13.03% (45 runs sampled)
- [All 1] rsvp-3.0.0 x 228,572 ops/sec ±10.84% (45 runs sampled)
- [All 1] rsvp-3.0.6 x 311,091 ops/sec ±9.73% (51 runs sampled)
- [All 1] rsvp x 369,172 ops/sec ±4.57% (43 runs sampled)

Running Benchmark Suite for test - All 2 ...
- [All 2] platform x 31,086 ops/sec ±5.71% (48 runs sampled)
- [All 2] rsvp-2.0.4 x 10,354 ops/sec ±10.83% (50 runs sampled)
- [All 2] rsvp-3.0.0 x 104,334 ops/sec ±6.45% (52 runs sampled)
- [All 2] rsvp-3.0.6 x 171,428 ops/sec ±7.14% (50 runs sampled)
- [All 2] rsvp x 316,104 ops/sec ±6.37% (54 runs sampled)

Running Benchmark Suite for test - All 10 ...
- [All 10] platform x 8,659 ops/sec ±5.19% (53 runs sampled)
- [All 10] rsvp-2.0.4 x 20,915 ops/sec ±9.44% (39 runs sampled)
- [All 10] rsvp-3.0.0 x 227,771 ops/sec ±7.86% (48 runs sampled)
- [All 10] rsvp-3.0.6 x 270,765 ops/sec ±11.72% (45 runs sampled)
- [All 10] rsvp x 443,783 ops/sec ±5.28% (48 runs sampled)

Running Benchmark Suite for test - All 100 ...
- [All 100] platform x 1,244 ops/sec ±5.07% (51 runs sampled)
- [All 100] rsvp-2.0.4 x 17,959 ops/sec ±9.60% (42 runs sampled)
- [All 100] rsvp-3.0.0 x 130,297 ops/sec ±16.25% (50 runs sampled)
- [All 100] rsvp-3.0.6 x 153,073 ops/sec ±7.61% (49 runs sampled)
- [All 100] rsvp x 284,933 ops/sec ±5.75% (50 runs sampled)

Running Benchmark Suite for test - All 1000 ...
- [All 1000] platform x 125 ops/sec ±5.12% (52 runs sampled)
- [All 1000] rsvp-2.0.4 x 6,519 ops/sec ±30.33% (40 runs sampled)
- [All 1000] rsvp-3.0.0 x 31,419 ops/sec ±6.42% (47 runs sampled)
- [All 1000] rsvp-3.0.6 x 23,182 ops/sec ±5.27% (46 runs sampled)
- [All 1000] rsvp x 41,246 ops/sec ±8.50% (41 runs sampled)

Running Benchmark Suite for test - All 10000 ...
- [All 10000] platform x 6.21 ops/sec ±8.65% (33 runs sampled)
- [All 10000] rsvp-2.0.4 x 1,603 ops/sec ±15.25% (50 runs sampled)
- [All 10000] rsvp-3.0.0 x 2,783 ops/sec ±6.36% (39 runs sampled)
- [All 10000] rsvp-3.0.6 x 2,691 ops/sec ±7.93% (52 runs sampled)
- [All 10000] rsvp x 4,873 ops/sec ±9.37% (50 runs sampled)

Running Benchmark Suite for test - All object 1 ...
- [All object 1] platform x 62,204 ops/sec ±6.82% (51 runs sampled)
- [All object 1] rsvp-2.0.4 x 18,818 ops/sec ±9.99% (37 runs sampled)
- [All object 1] rsvp-3.0.0 x 159,462 ops/sec ±5.40% (50 runs sampled)
- [All object 1] rsvp-3.0.6 x 138,120 ops/sec ±6.56% (39 runs sampled)
- [All object 1] rsvp x 286,668 ops/sec ±6.25% (50 runs sampled)

Running Benchmark Suite for test - All object 2 ...
- [All object 2] platform x 43,205 ops/sec ±3.27% (55 runs sampled)
- [All object 2] rsvp-2.0.4 x 23,508 ops/sec ±19.92% (22 runs sampled)
- [All object 2] rsvp-3.0.0 x 115,721 ops/sec ±6.85% (47 runs sampled)
- [All object 2] rsvp-3.0.6 x 145,395 ops/sec ±4.59% (49 runs sampled)
- [All object 2] rsvp x 192,970 ops/sec ±8.53% (30 runs sampled)

Running Benchmark Suite for test - All object 10 ...
- [All object 10] platform x 11,439 ops/sec ±4.80% (53 runs sampled)
- [All object 10] rsvp-2.0.4 x 25,869 ops/sec ±13.63% (49 runs sampled)
- [All object 10] rsvp-3.0.0 x 33,379 ops/sec ±9.16% (45 runs sampled)
- [All object 10] rsvp-3.0.6 x 26,962 ops/sec ±5.21% (52 runs sampled)
- [All object 10] rsvp x 70,673 ops/sec ±7.85% (46 runs sampled)

Running Benchmark Suite for test - All object 100 ...
- [All object 100] platform x 1,278 ops/sec ±5.45% (53 runs sampled)
- [All object 100] rsvp-2.0.4 x 19,990 ops/sec ±13.51% (39 runs sampled)
- [All object 100] rsvp-3.0.0 x 4,581 ops/sec ±7.73% (51 runs sampled)
- [All object 100] rsvp-3.0.6 x 4,934 ops/sec ±8.09% (48 runs sampled)
- [All object 100] rsvp x 8,959 ops/sec ±6.05% (46 runs sampled)

Running Benchmark Suite for test - All object 1000 ...
- [All object 1000] platform x 127 ops/sec ±3.52% (52 runs sampled)
- [All object 1000] rsvp-2.0.4 x 6,526 ops/sec ±10.40% (36 runs sampled)
- [All object 1000] rsvp-3.0.0 x 463 ops/sec ±9.11% (49 runs sampled)
- [All object 1000] rsvp-3.0.6 x 507 ops/sec ±8.08% (49 runs sampled)
- [All object 1000] rsvp x 990 ops/sec ±6.05% (50 runs sampled)

Running Benchmark Suite for test - All object 10000 ...
- [All object 10000] platform x 8.60 ops/sec ±7.72% (45 runs sampled)
- [All object 10000] rsvp-2.0.4 x 366 ops/sec ±16.04% (32 runs sampled)
- [All object 10000] rsvp-3.0.0 x 14.81 ops/sec ±16.51% (47 runs sampled)
- [All object 10000] rsvp-3.0.6 x 42.87 ops/sec ±10.36% (43 runs sampled)
- [All object 10000] rsvp x 58.32 ops/sec ±13.41% (44 runs sampled)

Running Benchmark Suite for test - All thenable 1 ...
- [All thenable 1] platform x 79,560 ops/sec ±3.83% (54 runs sampled)
- [All thenable 1] rsvp-2.0.4 x 1,925 ops/sec ±99.45% (5 runs sampled)
- [All thenable 1] rsvp-3.0.0 x 116,369 ops/sec ±25.11% (45 runs sampled)
- [All thenable 1] rsvp-3.0.6 x 65,783 ops/sec ±23.88% (26 runs sampled)
- [All thenable 1] rsvp x 131,863 ops/sec ±16.46% (49 runs sampled)

Running Benchmark Suite for test - All thenable 2 ...
- [All thenable 2] platform x 30,848 ops/sec ±1.89% (53 runs sampled)
- [All thenable 2] rsvp-2.0.4 x 1,832 ops/sec ±18.87% (17 runs sampled)
- [All thenable 2] rsvp-3.0.0 x 17,433 ops/sec ±2.62% (33 runs sampled)
- [All thenable 2] rsvp-3.0.6 x 13,023 ops/sec ±2.11% (48 runs sampled)
- [All thenable 2] rsvp x 91,849 ops/sec ±42.13% (13 runs sampled)

Running Benchmark Suite for test - All thenable 10 ...
- [All thenable 10] platform x 9,589 ops/sec ±5.60% (51 runs sampled)
- [All thenable 10] rsvp-2.0.4 x 673 ops/sec ±11.26% (32 runs sampled)
- [All thenable 10] rsvp-3.0.0 x 7,082 ops/sec ±2.85% (51 runs sampled)
- [All thenable 10] rsvp-3.0.6 x 8,146 ops/sec ±13.79% (38 runs sampled)
- [All thenable 10] rsvp x 38,762 ops/sec ±4.23% (53 runs sampled)

Running Benchmark Suite for test - All thenable 100 ...
- [All thenable 100] platform x 1,832 ops/sec ±6.92% (53 runs sampled)
- [All thenable 100] rsvp-2.0.4 x 195 ops/sec ±26.38% (17 runs sampled)
- [All thenable 100] rsvp-3.0.0 x 2,470 ops/sec ±35.56% (10 runs sampled)
- [All thenable 100] rsvp-3.0.6 x 4,362 ops/sec ±34.46% (35 runs sampled)
- [All thenable 100] rsvp x 12,997 ops/sec ±24.69% (49 runs sampled)

Running Benchmark Suite for test - All thenable 1000 ...
- [All thenable 1000] platform x 188 ops/sec ±5.97% (49 runs sampled)
- [All thenable 1000] rsvp-2.0.4 x 33.97 ops/sec ±20.36% (29 runs sampled)
- [All thenable 1000] rsvp-3.0.0 x 172 ops/sec ±54.74% (25 runs sampled)
- [All thenable 1000] rsvp-3.0.6 x 259 ops/sec ±40.37% (27 runs sampled)
- [All thenable 1000] rsvp x 288 ops/sec ±51.20% (49 runs sampled)

Running Benchmark Suite for test - All thenable 10000 ...
- [All thenable 10000] platform x 9.73 ops/sec ±5.01% (48 runs sampled)
- [All thenable 10000] rsvp-2.0.4 x 4.40 ops/sec ±29.96% (25 runs sampled)
- [All thenable 10000] rsvp-3.0.0 x 28.50 ops/sec ±52.28% (30 runs sampled)
- [All thenable 10000] rsvp-3.0.6 x 27.86 ops/sec ±59.24% (20 runs sampled)
- [All thenable 10000] rsvp x 127 ops/sec ±27.79% (44 runs sampled)

Running Benchmark Suite for test - Creation 1 ...
- [Creation 1] platform x 582,984 ops/sec ±4.60% (57 runs sampled)
- [Creation 1] rsvp-2.0.4 x 245,733 ops/sec ±9.52% (56 runs sampled)
- [Creation 1] rsvp-3.0.0 x 5,547,374 ops/sec ±2.93% (58 runs sampled)
- [Creation 1] rsvp-3.0.6 x 5,236,891 ops/sec ±2.19% (56 runs sampled)
- [Creation 1] rsvp x 4,835,237 ops/sec ±5.33% (55 runs sampled)

Running Benchmark Suite for test - filter false 1 ...
- [filter false 1] rsvp-3.0.6 x 114,896 ops/sec ±4.22% (55 runs sampled)
- [filter false 1] rsvp x 142,518 ops/sec ±4.02% (53 runs sampled)

Running Benchmark Suite for test - filter false 2 ...
- [filter false 2] rsvp-3.0.6 x 109,540 ops/sec ±7.90% (32 runs sampled)
- [filter false 2] rsvp x 140,934 ops/sec ±5.31% (51 runs sampled)

Running Benchmark Suite for test - filter false 10 ...
- [filter false 10] rsvp-3.0.6 x 102,817 ops/sec ±5.08% (53 runs sampled)
- [filter false 10] rsvp x 131,556 ops/sec ±4.30% (53 runs sampled)

Running Benchmark Suite for test - filter false 100 ...
- [filter false 100] rsvp-3.0.6 x 55,702 ops/sec ±4.96% (51 runs sampled)
- [filter false 100] rsvp x 78,282 ops/sec ±5.80% (50 runs sampled)

Running Benchmark Suite for test - filter false 1000 ...
- [filter false 1000] rsvp-3.0.6 x 10,573 ops/sec ±4.08% (53 runs sampled)
- [filter false 1000] rsvp x 16,416 ops/sec ±7.35% (49 runs sampled)

Running Benchmark Suite for test - filter false 10000 ...
- [filter false 10000] rsvp-3.0.6 x 1,202 ops/sec ±4.17% (51 runs sampled)
- [filter false 10000] rsvp x 1,907 ops/sec ±7.32% (49 runs sampled)

Running Benchmark Suite for test - filter with promiseFn 1 ...
- [filter with promiseFn 1] rsvp-3.0.6 x 95,276 ops/sec ±6.79% (51 runs sampled)
- [filter with promiseFn 1] rsvp x 116,584 ops/sec ±5.41% (50 runs sampled)

Running Benchmark Suite for test - filter with promiseFn 2 ...
- [filter with promiseFn 2] rsvp-3.0.6 x 76,926 ops/sec ±5.51% (49 runs sampled)
- [filter with promiseFn 2] rsvp x 102,216 ops/sec ±6.32% (48 runs sampled)

Running Benchmark Suite for test - filter with promiseFn 10 ...
- [filter with promiseFn 10] rsvp-3.0.6 x 36,068 ops/sec ±6.91% (50 runs sampled)
- [filter with promiseFn 10] rsvp x 52,145 ops/sec ±5.24% (47 runs sampled)

Running Benchmark Suite for test - filter with promiseFn 100 ...
- [filter with promiseFn 100] rsvp-3.0.6 x 4,725 ops/sec ±8.44% (35 runs sampled)
- [filter with promiseFn 100] rsvp x 8,087 ops/sec ±7.25% (49 runs sampled)

Running Benchmark Suite for test - filter with promiseFn 1000 ...
- [filter with promiseFn 1000] rsvp-3.0.6 x 506 ops/sec ±7.90% (49 runs sampled)
- [filter with promiseFn 1000] rsvp x 917 ops/sec ±6.51% (51 runs sampled)

Running Benchmark Suite for test - filter with promiseFn 10000 ...
- [filter with promiseFn 10000] rsvp-3.0.6 x 51.77 ops/sec ±7.66% (51 runs sampled)
- [filter with promiseFn 10000] rsvp x 90.41 ops/sec ±6.26% (49 runs sampled)

Running Benchmark Suite for test - filter true 1 ...
- [filter true 1] rsvp-3.0.6 x 113,008 ops/sec ±5.33% (45 runs sampled)
- [filter true 1] rsvp x 138,437 ops/sec ±6.05% (49 runs sampled)

Running Benchmark Suite for test - filter true 2 ...
- [filter true 2] bluebird x 390,454 ops/sec ±5.70% (54 runs sampled)
- [filter true 2] rsvp-3.0.6 x 115,404 ops/sec ±5.11% (49 runs sampled)
- [filter true 2] rsvp x 137,926 ops/sec ±4.95% (51 runs sampled)

Running Benchmark Suite for test - filter true 10 ...
- [filter true 10] rsvp-3.0.6 x 100,666 ops/sec ±5.94% (54 runs sampled)
- [filter true 10] rsvp x 126,957 ops/sec ±4.44% (50 runs sampled)

Running Benchmark Suite for test - filter true 100 ...
- [filter true 100] bluebird x 88,265 ops/sec ±4.25% (52 runs sampled)
- [filter true 100] rsvp-3.0.6 x 52,095 ops/sec ±8.04% (49 runs sampled)
- [filter true 100] rsvp x 73,543 ops/sec ±5.03% (50 runs sampled)
Fastest for filter true 100 is
Array[1]
Running Benchmark Suite for test - filter true 1000 ...
- [filter true 1000] bluebird x 11,540 ops/sec ±4.82% (52 runs sampled)
- [filter true 1000] rsvp-3.0.6 x 8,675 ops/sec ±7.06% (49 runs sampled)
- [filter true 1000] rsvp x 14,303 ops/sec ±7.74% (50 runs sampled)

Running Benchmark Suite for test - filter true 10000 ...
- [filter true 10000] rsvp-3.0.6 x 1,072 ops/sec ±5.18% (50 runs sampled)
- [filter true 10000] rsvp x 1,523 ops/sec ±9.56% (47 runs sampled)

Running Benchmark Suite for test - Reject 1 ...
- [Reject 1] rsvp-2.0.4 x 31,789 ops/sec ±7.86% (46 runs sampled)
- [Reject 1] rsvp-3.0.0 x 302,989 ops/sec ±7.01% (47 runs sampled)
- [Reject 1] rsvp-3.0.6 x 394,058 ops/sec ±7.34% (50 runs sampled)
- [Reject 1] rsvp x 480,353 ops/sec ±4.40% (51 runs sampled)

Running Benchmark Suite for test - Resolve 1 ...
- [Resolve 1] rsvp-2.0.4 x 35,270 ops/sec ±7.07% (48 runs sampled)
- [Resolve 1] rsvp-3.0.0 x 305,753 ops/sec ±7.85% (49 runs sampled)
- [Resolve 1] rsvp-3.0.6 x 378,555 ops/sec ±6.15% (47 runs sampled)
- [Resolve 1] rsvp x 451,985 ops/sec ±3.89% (48 runs sampled)

Running Benchmark Suite for test - Resolve Promise 1 ...
- [Resolve Promise 1] rsvp-2.0.4 x 4,575 ops/sec ±46.04% (14 runs sampled)
- [Resolve Promise 1] rsvp-3.0.0 x 154,747 ops/sec ±9.52% (49 runs sampled)
- [Resolve Promise 1] rsvp-3.0.6 x 189,956 ops/sec ±11.03% (45 runs sampled)
- [Resolve Promise 1] rsvp x 329,175 ops/sec ±2.72% (53 runs sampled)