Commit 569767e
stream: add fast paths for webstreams read and pipeTo
Add internal fast paths to improve webstreams performance without
changing the public API or breaking spec compliance.
1. ReadableStreamDefaultReader.read() fast path:
When data is already buffered in the controller's queue, return
PromiseResolve() directly without creating a DefaultReadRequest
object. This is spec-compliant because read() returns a Promise,
and resolved promises still run callbacks in the microtask queue.
2. pipeTo() batch read fast path:
When data is buffered, batch reads directly from the controller
queue up to highWaterMark without creating
PipeToReadableStreamReadRequest objects per chunk. Respects
backpressure by checking desiredSize after each write.
Benchmark results:
- pipeTo: ~11% faster (***)
- buffered read(): ~17-20% faster (***)
Co-Authored-By: Malte Ubl <malte@vercel.com>
PR-URL: #61807
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>1 parent 240b512 commit 569767eCopy full SHA for 569767e
2 files changed
+132Lines changed: 132 additions & 0 deletions
File tree
Expand file treeCollapse file tree
Open diff view settings
Filter options
- benchmark/webstreams
- lib/internal/webstreams
Expand file treeCollapse file tree
Open diff view settings
Collapse file
benchmark/webstreams/readable-read-buffered.js
Copy file name to clipboard+54Lines changed: 54 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | + |
Collapse file
lib/internal/webstreams/readablestream.js
Copy file name to clipboardExpand all lines: lib/internal/webstreams/readablestream.js+78Lines changed: 78 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
860 | 860 | |
861 | 861 | |
862 | 862 | |
| 863 | + |
| 864 | + |
| 865 | + |
| 866 | + |
| 867 | + |
| 868 | + |
| 869 | + |
| 870 | + |
| 871 | + |
| 872 | + |
| 873 | + |
| 874 | + |
| 875 | + |
| 876 | + |
| 877 | + |
| 878 | + |
| 879 | + |
| 880 | + |
| 881 | + |
| 882 | + |
| 883 | + |
| 884 | + |
| 885 | + |
| 886 | + |
| 887 | + |
863 | 888 | |
864 | 889 | |
865 | 890 | |
| ||
1286 | 1311 | |
1287 | 1312 | |
1288 | 1313 | |
| 1314 | + |
| 1315 | + |
1289 | 1316 | |
1290 | 1317 | |
1291 | 1318 | |
| ||
1510 | 1537 | |
1511 | 1538 | |
1512 | 1539 | |
| 1540 | + |
| 1541 | + |
| 1542 | + |
| 1543 | + |
| 1544 | + |
| 1545 | + |
| 1546 | + |
| 1547 | + |
| 1548 | + |
| 1549 | + |
| 1550 | + |
| 1551 | + |
| 1552 | + |
| 1553 | + |
| 1554 | + |
| 1555 | + |
| 1556 | + |
| 1557 | + |
| 1558 | + |
| 1559 | + |
| 1560 | + |
| 1561 | + |
| 1562 | + |
| 1563 | + |
| 1564 | + |
| 1565 | + |
| 1566 | + |
| 1567 | + |
| 1568 | + |
| 1569 | + |
| 1570 | + |
| 1571 | + |
| 1572 | + |
| 1573 | + |
| 1574 | + |
| 1575 | + |
| 1576 | + |
| 1577 | + |
| 1578 | + |
| 1579 | + |
| 1580 | + |
| 1581 | + |
| 1582 | + |
| 1583 | + |
| 1584 | + |
| 1585 | + |
| 1586 | + |
| 1587 | + |
| 1588 | + |
| 1589 | + |
| 1590 | + |
1513 | 1591 | |
1514 | 1592 | |
1515 | 1593 | |
|
0 commit comments