Skip to content

Commit fe3dfbc

Browse files
committed
demonstrate new publisher
depends on #3784 The proposed new publisher does not use the event loop to manage AsyncRecord dependencies => and so if multiple items within a stream are released from publishing because their parent has just been published, they are all released at once. Another difference is that different sets are used to store the AsyncRecords that are pending vs ready for publishing, etc. This provides a performance benefit in that on a call to next, the set of all AsyncRecords is not inspected. 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. The subscribe algorithm used does not use Promise.race -- this may also 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)
1 parent 26002c8 commit fe3dfbc

File tree

4 files changed

+195
-182
lines changed

4 files changed

+195
-182
lines changed

src/execution/__tests__/defer-test.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -605,11 +605,6 @@ describe('Execute: defer directive', () => {
605605
data: { slowField: 'slow', friends: [{}, {}, {}] },
606606
path: ['hero'],
607607
},
608-
],
609-
hasNext: true,
610-
},
611-
{
612-
incremental: [
613608
{ data: { name: 'Han' }, path: ['hero', 'friends', 0] },
614609
{ data: { name: 'Leia' }, path: ['hero', 'friends', 1] },
615610
{ data: { name: 'C-3PO' }, path: ['hero', 'friends', 2] },
@@ -653,11 +648,6 @@ describe('Execute: defer directive', () => {
653648
},
654649
path: ['hero'],
655650
},
656-
],
657-
hasNext: true,
658-
},
659-
{
660-
incremental: [
661651
{ data: { name: 'Han' }, path: ['hero', 'friends', 0] },
662652
{ data: { name: 'Leia' }, path: ['hero', 'friends', 1] },
663653
{ data: { name: 'C-3PO' }, path: ['hero', 'friends', 2] },

src/execution/__tests__/stream-test.ts

Lines changed: 21 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,10 @@ describe('Execute: stream directive', () => {
151151
hasNext: true,
152152
},
153153
{
154-
incremental: [{ items: ['banana'], path: ['scalarList', 1] }],
155-
hasNext: true,
156-
},
157-
{
158-
incremental: [{ items: ['coconut'], path: ['scalarList', 2] }],
154+
incremental: [
155+
{ items: ['banana'], path: ['scalarList', 1] },
156+
{ items: ['coconut'], path: ['scalarList', 2] },
157+
],
159158
hasNext: false,
160159
},
161160
]);
@@ -173,15 +172,11 @@ describe('Execute: stream directive', () => {
173172
hasNext: true,
174173
},
175174
{
176-
incremental: [{ items: ['apple'], path: ['scalarList', 0] }],
177-
hasNext: true,
178-
},
179-
{
180-
incremental: [{ items: ['banana'], path: ['scalarList', 1] }],
181-
hasNext: true,
182-
},
183-
{
184-
incremental: [{ items: ['coconut'], path: ['scalarList', 2] }],
175+
incremental: [
176+
{ items: ['apple'], path: ['scalarList', 0] },
177+
{ items: ['banana'], path: ['scalarList', 1] },
178+
{ items: ['coconut'], path: ['scalarList', 2] },
179+
],
185180
hasNext: false,
186181
},
187182
]);
@@ -230,11 +225,6 @@ describe('Execute: stream directive', () => {
230225
path: ['scalarList', 1],
231226
label: 'scalar-stream',
232227
},
233-
],
234-
hasNext: true,
235-
},
236-
{
237-
incremental: [
238228
{
239229
items: ['coconut'],
240230
path: ['scalarList', 2],
@@ -296,11 +286,6 @@ describe('Execute: stream directive', () => {
296286
items: [['banana', 'banana', 'banana']],
297287
path: ['scalarListList', 1],
298288
},
299-
],
300-
hasNext: true,
301-
},
302-
{
303-
incremental: [
304289
{
305290
items: [['coconut', 'coconut', 'coconut']],
306291
path: ['scalarListList', 2],
@@ -379,20 +364,10 @@ describe('Execute: stream directive', () => {
379364
items: [{ name: 'Luke', id: '1' }],
380365
path: ['friendList', 0],
381366
},
382-
],
383-
hasNext: true,
384-
},
385-
{
386-
incremental: [
387367
{
388368
items: [{ name: 'Han', id: '2' }],
389369
path: ['friendList', 1],
390370
},
391-
],
392-
hasNext: true,
393-
},
394-
{
395-
incremental: [
396371
{
397372
items: [{ name: 'Leia', id: '3' }],
398373
path: ['friendList', 2],
@@ -483,11 +458,6 @@ describe('Execute: stream directive', () => {
483458
},
484459
],
485460
},
486-
],
487-
hasNext: true,
488-
},
489-
{
490-
incremental: [
491461
{
492462
items: [{ name: 'Leia', id: '3' }],
493463
path: ['friendList', 2],
@@ -585,9 +555,6 @@ describe('Execute: stream directive', () => {
585555
path: ['friendList', 2],
586556
},
587557
],
588-
hasNext: true,
589-
},
590-
{
591558
hasNext: false,
592559
},
593560
]);
@@ -627,7 +594,7 @@ describe('Execute: stream directive', () => {
627594
}
628595
}
629596
`);
630-
const result = await completeAsync(document, 3, {
597+
const result = await completeAsync(document, 2, {
631598
async *friendList() {
632599
yield await Promise.resolve(friends[0]);
633600
yield await Promise.resolve(friends[1]);
@@ -656,10 +623,9 @@ describe('Execute: stream directive', () => {
656623
path: ['friendList', 2],
657624
},
658625
],
659-
hasNext: true,
626+
hasNext: false,
660627
},
661628
},
662-
{ done: false, value: { hasNext: false } },
663629
{ done: true, value: undefined },
664630
]);
665631
});
@@ -887,11 +853,6 @@ describe('Execute: stream directive', () => {
887853
},
888854
],
889855
},
890-
],
891-
hasNext: true,
892-
},
893-
{
894-
incremental: [
895856
{
896857
items: [{ nonNullName: 'Han' }],
897858
path: ['friendList', 2],
@@ -980,11 +941,6 @@ describe('Execute: stream directive', () => {
980941
},
981942
],
982943
},
983-
],
984-
hasNext: true,
985-
},
986-
{
987-
incremental: [
988944
{
989945
items: [{ nonNullName: 'Han' }],
990946
path: ['friendList', 2],
@@ -1140,6 +1096,10 @@ describe('Execute: stream directive', () => {
11401096
},
11411097
{
11421098
incremental: [
1099+
{
1100+
items: [{ name: 'Luke' }],
1101+
path: ['nestedObject', 'nestedFriendList', 0],
1102+
},
11431103
{
11441104
data: { scalarField: null },
11451105
path: ['otherNestedObject'],
@@ -1151,10 +1111,6 @@ describe('Execute: stream directive', () => {
11511111
},
11521112
],
11531113
},
1154-
{
1155-
items: [{ name: 'Luke' }],
1156-
path: ['nestedObject', 'nestedFriendList', 0],
1157-
},
11581114
],
11591115
hasNext: false,
11601116
},
@@ -1258,9 +1214,6 @@ describe('Execute: stream directive', () => {
12581214
],
12591215
},
12601216
],
1261-
hasNext: true,
1262-
},
1263-
{
12641217
hasNext: false,
12651218
},
12661219
]);
@@ -1407,9 +1360,6 @@ describe('Execute: stream directive', () => {
14071360
path: ['friendList', 2],
14081361
},
14091362
],
1410-
hasNext: true,
1411-
},
1412-
{
14131363
hasNext: false,
14141364
},
14151365
]);
@@ -1463,15 +1413,6 @@ describe('Execute: stream directive', () => {
14631413
data: { scalarField: 'slow', nestedFriendList: [] },
14641414
path: ['nestedObject'],
14651415
},
1466-
],
1467-
hasNext: true,
1468-
},
1469-
done: false,
1470-
});
1471-
const result3 = await iterator.next();
1472-
expectJSON(result3).toDeepEqual({
1473-
value: {
1474-
incremental: [
14751416
{
14761417
items: [{ name: 'Luke' }],
14771418
path: ['nestedObject', 'nestedFriendList', 0],
@@ -1481,8 +1422,8 @@ describe('Execute: stream directive', () => {
14811422
},
14821423
done: false,
14831424
});
1484-
const result4 = await iterator.next();
1485-
expectJSON(result4).toDeepEqual({
1425+
const result3 = await iterator.next();
1426+
expectJSON(result3).toDeepEqual({
14861427
value: {
14871428
incremental: [
14881429
{
@@ -1494,13 +1435,13 @@ describe('Execute: stream directive', () => {
14941435
},
14951436
done: false,
14961437
});
1497-
const result5 = await iterator.next();
1498-
expectJSON(result5).toDeepEqual({
1438+
const result4 = await iterator.next();
1439+
expectJSON(result4).toDeepEqual({
14991440
value: { hasNext: false },
15001441
done: false,
15011442
});
1502-
const result6 = await iterator.next();
1503-
expectJSON(result6).toDeepEqual({
1443+
const result5 = await iterator.next();
1444+
expectJSON(result5).toDeepEqual({
15041445
value: undefined,
15051446
done: true,
15061447
});

0 commit comments

Comments
 (0)