Repository navigation
Commit 0ff1bfc
committed
stream: cut promise churn in webstreams hot paths
Three related reductions on the per-chunk paths:
Wrap user sink.write and source.pull callbacks without coercing their
result into a promise. When the callback returns a non-thenable (the
common synchronous case), fulfillment is guaranteed and no then() lookup
is observable, so the fulfilled reaction is enqueued through a single
shared resolved promise at the exact microtask position the coerced
promise's reaction would have had, skipping the implicit async-wrapper
promise per chunk. Thenable results go through PromiseResolve(), which
matches the spec's "a promise resolved with" conversion (identity for
native promises).
Park pipeTo's pump on backpressure by installing a record that
duck-types the writer's lazily-materialized [[readyPromise]] record and
whose resolve function is the pump continuation itself. Backpressure
clearing then resumes the pump directly instead of materializing a fresh
promise record plus reaction per flip, and the pump no longer schedules
a microtask per batch. writableStreamUpdateBackpressure publishes the
new backpressure state before resolving the ready record so the pump
observes the updated value.
Replace queueMicrotask() on the pipeTo and tee chunk-forwarding paths
with a reaction on the shared resolved promise, which enqueues the
continuation at the same position without the per-call scheduling
overhead.
pipe-to improves by 8-14% across all benchmark configurations, with
readable-read and tee also improving in spot runs.
Signed-off-by: Matteo Collina <hello@matteocollina.com>1 parent c455f65 commit 0ff1bfc
3 files changed
Lines changed: 126 additions & 25 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| 104 | + | |
104 | 105 | | |
105 | 106 | | |
106 | 107 | | |
| |||
110 | 111 | | |
111 | 112 | | |
112 | 113 | | |
| 114 | + | |
113 | 115 | | |
114 | 116 | | |
115 | 117 | | |
| |||
121 | 123 | | |
122 | 124 | | |
123 | 125 | | |
| 126 | + | |
124 | 127 | | |
125 | 128 | | |
126 | 129 | | |
| |||
137 | 140 | | |
138 | 141 | | |
139 | 142 | | |
140 | | - | |
141 | 143 | | |
142 | 144 | | |
143 | 145 | | |
| |||
1674 | 1676 | | |
1675 | 1677 | | |
1676 | 1678 | | |
| 1679 | + | |
1677 | 1680 | | |
1678 | 1681 | | |
1679 | 1682 | | |
1680 | 1683 | | |
1681 | 1684 | | |
| 1685 | + | |
| 1686 | + | |
| 1687 | + | |
| 1688 | + | |
| 1689 | + | |
| 1690 | + | |
| 1691 | + | |
| 1692 | + | |
| 1693 | + | |
| 1694 | + | |
| 1695 | + | |
| 1696 | + | |
| 1697 | + | |
| 1698 | + | |
| 1699 | + | |
| 1700 | + | |
| 1701 | + | |
| 1702 | + | |
| 1703 | + | |
1682 | 1704 | | |
1683 | 1705 | | |
1684 | 1706 | | |
| |||
1690 | 1712 | | |
1691 | 1713 | | |
1692 | 1714 | | |
1693 | | - | |
1694 | | - | |
1695 | | - | |
1696 | | - | |
| 1715 | + | |
1697 | 1716 | | |
1698 | 1717 | | |
1699 | 1718 | | |
| |||
1738 | 1757 | | |
1739 | 1758 | | |
1740 | 1759 | | |
1741 | | - | |
1742 | | - | |
1743 | | - | |
| 1760 | + | |
| 1761 | + | |
| 1762 | + | |
| 1763 | + | |
| 1764 | + | |
| 1765 | + | |
| 1766 | + | |
| 1767 | + | |
| 1768 | + | |
| 1769 | + | |
| 1770 | + | |
| 1771 | + | |
1744 | 1772 | | |
1745 | 1773 | | |
1746 | 1774 | | |
| |||
1752 | 1780 | | |
1753 | 1781 | | |
1754 | 1782 | | |
1755 | | - | |
| 1783 | + | |
1756 | 1784 | | |
1757 | 1785 | | |
1758 | 1786 | | |
| |||
1867 | 1895 | | |
1868 | 1896 | | |
1869 | 1897 | | |
1870 | | - | |
| 1898 | + | |
1871 | 1899 | | |
1872 | 1900 | | |
1873 | 1901 | | |
| |||
2020 | 2048 | | |
2021 | 2049 | | |
2022 | 2050 | | |
2023 | | - | |
| 2051 | + | |
2024 | 2052 | | |
2025 | 2053 | | |
2026 | 2054 | | |
| |||
2709 | 2737 | | |
2710 | 2738 | | |
2711 | 2739 | | |
2712 | | - | |
2713 | | - | |
| 2740 | + | |
| 2741 | + | |
| 2742 | + | |
| 2743 | + | |
| 2744 | + | |
| 2745 | + | |
| 2746 | + | |
| 2747 | + | |
| 2748 | + | |
| 2749 | + | |
| 2750 | + | |
| 2751 | + | |
2714 | 2752 | | |
2715 | 2753 | | |
2716 | 2754 | | |
| |||
2836 | 2874 | | |
2837 | 2875 | | |
2838 | 2876 | | |
2839 | | - | |
| 2877 | + | |
2840 | 2878 | | |
2841 | 2879 | | |
2842 | 2880 | | |
| |||
3529 | 3567 | | |
3530 | 3568 | | |
3531 | 3569 | | |
3532 | | - | |
3533 | | - | |
| 3570 | + | |
| 3571 | + | |
| 3572 | + | |
| 3573 | + | |
| 3574 | + | |
| 3575 | + | |
| 3576 | + | |
| 3577 | + | |
| 3578 | + | |
3534 | 3579 | | |
3535 | 3580 | | |
3536 | 3581 | | |
| |||
3710 | 3755 | | |
3711 | 3756 | | |
3712 | 3757 | | |
3713 | | - | |
| 3758 | + | |
3714 | 3759 | | |
3715 | 3760 | | |
3716 | 3761 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
338 | 338 | | |
339 | 339 | | |
340 | 340 | | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
341 | 375 | | |
342 | 376 | | |
343 | 377 | | |
| |||
386 | 420 | | |
387 | 421 | | |
388 | 422 | | |
389 | | - | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
390 | 427 | | |
391 | 428 | | |
392 | 429 | | |
393 | | - | |
| 430 | + | |
394 | 431 | | |
395 | 432 | | |
396 | 433 | | |
| |||
411 | 448 | | |
412 | 449 | | |
413 | 450 | | |
| 451 | + | |
| 452 | + | |
414 | 453 | | |
415 | 454 | | |
416 | 455 | | |
| |||
421 | 460 | | |
422 | 461 | | |
423 | 462 | | |
| 463 | + | |
424 | 464 | | |
425 | 465 | | |
426 | 466 | | |
| |||
435 | 475 | | |
436 | 476 | | |
437 | 477 | | |
| 478 | + | |
438 | 479 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
| 59 | + | |
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| 81 | + | |
81 | 82 | | |
82 | 83 | | |
83 | 84 | | |
| |||
769 | 770 | | |
770 | 771 | | |
771 | 772 | | |
772 | | - | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
773 | 779 | | |
774 | 780 | | |
775 | 781 | | |
| |||
778 | 784 | | |
779 | 785 | | |
780 | 786 | | |
781 | | - | |
782 | 787 | | |
783 | 788 | | |
784 | 789 | | |
| |||
1197 | 1202 | | |
1198 | 1203 | | |
1199 | 1204 | | |
1200 | | - | |
1201 | | - | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
1202 | 1217 | | |
1203 | 1218 | | |
1204 | 1219 | | |
| |||
1323 | 1338 | | |
1324 | 1339 | | |
1325 | 1340 | | |
1326 | | - | |
| 1341 | + | |
1327 | 1342 | | |
1328 | 1343 | | |
1329 | 1344 | | |
| |||
0 commit comments