Commit e134bf3
committed
introduce new Publisher for incremental delivery
Depends on #3784
The proposed new Publisher:
1. does not use the event loop to manage AsyncRecord dependencies
2. uses separate sets to store pending vs ready AsyncRecords
3. does not use `Promise.race`
## No event loop for managing AsyncRecord dependencies
The current Publisher wraps every AsyncRecord result in a promise that only resolves after the parent AsyncRecord resolves. If multiple items within a stream are released for publishing because their parent has just been published, the stream cannot be in its entirety until after all of these promises unwind.
The new Publisher keeps track of dependencies manually. When an AsyncRecord is pushed by the publisher, all of its dependent AsyncRecords are synchronously pushed, repeating as necessary, without using the event loop.
## Separate sets for pending vs ready AsyncRecords
The current publisher inspects all pending AsyncRecords whenever any of them resolves. All that are completed are added to the response. The new Publisher moves AsyncRecords from the pending set to the ready set as they are pushed, so that on each call to next, only the ready set must be iterated.
As a side-effect of this change, the incremental array is ordered by which items are ready for delivery first, and not by the initial document.
This seems like a worthwhile tradeoff, and is still adherent to the spec, as far as I can tell.
## No `Promise.race`
The old Publisher uses `Promise.race` as the trigger to determine whether payloads are ready. The new Publisher uses a single triggering promise that is triggered whenever an AsyncRecord is pushed, and then reset. This may be beneficial as the implementation of `Promise.race` within V8 has a known memory leak for long-running promises. (see https://bugs.chromium.org/p/v8/issues/detail?id=9858). An alternative would be to utilize @brainkim 's memory-safe version detailed in that issue.1 parent f92d86d commit e134bf3
File tree
4 files changed
+173
-154
lines changed- src/execution
- __tests__
4 files changed
+173
-154
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
605 | 605 | | |
606 | 606 | | |
607 | 607 | | |
608 | | - | |
609 | | - | |
610 | | - | |
611 | | - | |
612 | | - | |
613 | 608 | | |
614 | 609 | | |
615 | 610 | | |
| |||
653 | 648 | | |
654 | 649 | | |
655 | 650 | | |
656 | | - | |
657 | | - | |
658 | | - | |
659 | | - | |
660 | | - | |
661 | 651 | | |
662 | 652 | | |
663 | 653 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
159 | 158 | | |
160 | 159 | | |
161 | 160 | | |
| |||
173 | 172 | | |
174 | 173 | | |
175 | 174 | | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
185 | 180 | | |
186 | 181 | | |
187 | 182 | | |
| |||
230 | 225 | | |
231 | 226 | | |
232 | 227 | | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | 228 | | |
239 | 229 | | |
240 | 230 | | |
| |||
296 | 286 | | |
297 | 287 | | |
298 | 288 | | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | 289 | | |
305 | 290 | | |
306 | 291 | | |
| |||
379 | 364 | | |
380 | 365 | | |
381 | 366 | | |
382 | | - | |
383 | | - | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | 367 | | |
388 | 368 | | |
389 | 369 | | |
390 | 370 | | |
391 | | - | |
392 | | - | |
393 | | - | |
394 | | - | |
395 | | - | |
396 | 371 | | |
397 | 372 | | |
398 | 373 | | |
| |||
628 | 603 | | |
629 | 604 | | |
630 | 605 | | |
631 | | - | |
632 | | - | |
633 | | - | |
634 | 606 | | |
635 | 607 | | |
636 | 608 | | |
| |||
670 | 642 | | |
671 | 643 | | |
672 | 644 | | |
673 | | - | |
| 645 | + | |
674 | 646 | | |
675 | 647 | | |
676 | 648 | | |
| |||
699 | 671 | | |
700 | 672 | | |
701 | 673 | | |
702 | | - | |
| 674 | + | |
703 | 675 | | |
704 | 676 | | |
705 | | - | |
706 | 677 | | |
707 | 678 | | |
708 | 679 | | |
| |||
930 | 901 | | |
931 | 902 | | |
932 | 903 | | |
933 | | - | |
934 | | - | |
935 | | - | |
936 | | - | |
937 | | - | |
938 | 904 | | |
939 | 905 | | |
940 | 906 | | |
| |||
1107 | 1073 | | |
1108 | 1074 | | |
1109 | 1075 | | |
1110 | | - | |
1111 | | - | |
1112 | | - | |
1113 | | - | |
1114 | | - | |
1115 | 1076 | | |
1116 | 1077 | | |
1117 | 1078 | | |
| |||
1276 | 1237 | | |
1277 | 1238 | | |
1278 | 1239 | | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
1279 | 1244 | | |
1280 | 1245 | | |
1281 | 1246 | | |
| |||
1287 | 1252 | | |
1288 | 1253 | | |
1289 | 1254 | | |
1290 | | - | |
1291 | | - | |
1292 | | - | |
1293 | | - | |
1294 | 1255 | | |
1295 | 1256 | | |
1296 | 1257 | | |
| |||
1397 | 1358 | | |
1398 | 1359 | | |
1399 | 1360 | | |
1400 | | - | |
1401 | | - | |
1402 | | - | |
1403 | 1361 | | |
1404 | 1362 | | |
1405 | 1363 | | |
| |||
1546 | 1504 | | |
1547 | 1505 | | |
1548 | 1506 | | |
1549 | | - | |
1550 | | - | |
1551 | | - | |
1552 | 1507 | | |
1553 | 1508 | | |
1554 | 1509 | | |
| |||
1602 | 1557 | | |
1603 | 1558 | | |
1604 | 1559 | | |
1605 | | - | |
1606 | | - | |
1607 | | - | |
1608 | | - | |
1609 | | - | |
1610 | | - | |
1611 | | - | |
1612 | | - | |
1613 | | - | |
1614 | 1560 | | |
1615 | 1561 | | |
1616 | 1562 | | |
| |||
1620 | 1566 | | |
1621 | 1567 | | |
1622 | 1568 | | |
1623 | | - | |
1624 | | - | |
| 1569 | + | |
| 1570 | + | |
1625 | 1571 | | |
1626 | 1572 | | |
1627 | 1573 | | |
| |||
1633 | 1579 | | |
1634 | 1580 | | |
1635 | 1581 | | |
1636 | | - | |
1637 | | - | |
| 1582 | + | |
| 1583 | + | |
1638 | 1584 | | |
1639 | 1585 | | |
1640 | 1586 | | |
1641 | | - | |
1642 | | - | |
| 1587 | + | |
| 1588 | + | |
1643 | 1589 | | |
1644 | 1590 | | |
1645 | 1591 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2095 | 2095 | | |
2096 | 2096 | | |
2097 | 2097 | | |
2098 | | - | |
2099 | 2098 | | |
2100 | 2099 | | |
2101 | | - | |
2102 | | - | |
2103 | | - | |
| 2100 | + | |
| 2101 | + | |
| 2102 | + | |
| 2103 | + | |
| 2104 | + | |
| 2105 | + | |
2104 | 2106 | | |
2105 | 2107 | | |
2106 | 2108 | | |
| |||
2112 | 2114 | | |
2113 | 2115 | | |
2114 | 2116 | | |
2115 | | - | |
2116 | | - | |
2117 | | - | |
| 2117 | + | |
| 2118 | + | |
2118 | 2119 | | |
2119 | | - | |
2120 | | - | |
2121 | | - | |
2122 | | - | |
2123 | | - | |
2124 | | - | |
2125 | | - | |
2126 | | - | |
2127 | 2120 | | |
2128 | 2121 | | |
2129 | 2122 | | |
2130 | | - | |
2131 | | - | |
2132 | | - | |
2133 | | - | |
2134 | | - | |
2135 | | - | |
| 2123 | + | |
| 2124 | + | |
2136 | 2125 | | |
2137 | 2126 | | |
2138 | 2127 | | |
| |||
2142 | 2131 | | |
2143 | 2132 | | |
2144 | 2133 | | |
2145 | | - | |
2146 | 2134 | | |
2147 | 2135 | | |
2148 | 2136 | | |
2149 | | - | |
2150 | | - | |
2151 | | - | |
| 2137 | + | |
| 2138 | + | |
| 2139 | + | |
| 2140 | + | |
| 2141 | + | |
| 2142 | + | |
2152 | 2143 | | |
2153 | 2144 | | |
2154 | 2145 | | |
| |||
2163 | 2154 | | |
2164 | 2155 | | |
2165 | 2156 | | |
2166 | | - | |
2167 | | - | |
2168 | | - | |
| 2157 | + | |
| 2158 | + | |
2169 | 2159 | | |
2170 | | - | |
2171 | | - | |
2172 | | - | |
2173 | | - | |
2174 | | - | |
2175 | | - | |
2176 | | - | |
2177 | | - | |
2178 | 2160 | | |
2179 | 2161 | | |
2180 | 2162 | | |
2181 | | - | |
2182 | | - | |
2183 | | - | |
2184 | | - | |
2185 | | - | |
2186 | | - | |
| 2163 | + | |
| 2164 | + | |
2187 | 2165 | | |
2188 | 2166 | | |
2189 | 2167 | | |
| |||
0 commit comments