Skip to content

Commit

Permalink
remove permanent tracking of all ancestors
Browse files Browse the repository at this point in the history
in favor of resolution at runtime

this is a tradeoff of theoretical performance gain vs code simplification
  • Loading branch information
yaacovCR committed Dec 15, 2023
1 parent cff3477 commit 40f07e2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
14 changes: 13 additions & 1 deletion src/execution/buildFieldPlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function buildFieldPlan(
for (const target of targetSet) {
if (
target === undefined ||
target.ancestors.every((ancestor) => !targetSet.has(ancestor))
getAncestors(target).every((ancestor) => !targetSet.has(ancestor))
) {
maskingTargetList.push(target);
}
Expand Down Expand Up @@ -145,3 +145,15 @@ export function buildFieldPlan(
newDeferUsages: Array.from(newDeferUsages),
};
}

function getAncestors(
deferUsage: DeferUsage,
): ReadonlyArray<DeferUsage | undefined> {
let parentDeferUsage: DeferUsage | undefined = deferUsage.parentDeferUsage;
const ancestors: Array<DeferUsage | undefined> = [parentDeferUsage];
while (parentDeferUsage !== undefined) {
parentDeferUsage = parentDeferUsage.parentDeferUsage;
ancestors.unshift(parentDeferUsage);
}
return ancestors;
}
7 changes: 2 additions & 5 deletions src/execution/collectFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { getDirectiveValues } from './values.js';

export interface DeferUsage {
label: string | undefined;
ancestors: ReadonlyArray<DeferUsage | undefined>;
parentDeferUsage: DeferUsage | undefined;
}

export interface FieldDetails {
Expand Down Expand Up @@ -242,10 +242,7 @@ function getDeferUsage(

return {
label: typeof defer.label === 'string' ? defer.label : undefined,
ancestors:
parentDeferUsage === undefined
? [undefined]
: [parentDeferUsage, ...parentDeferUsage.ancestors],
parentDeferUsage,
};
}

Expand Down
3 changes: 1 addition & 2 deletions src/execution/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1464,8 +1464,7 @@ function addNewDeferredFragments(

// For each new deferUsage object:
for (const newDeferUsage of newDeferUsages) {
// DeferUsage objects track their parent targets; the immediate parent is always the first member of this list.
const parentTarget = newDeferUsage.ancestors[0];
const parentTarget = newDeferUsage.parentDeferUsage;

// If the parent target is defined, the parent target is a DeferUsage object and
// the parent result record is the DeferredFragmentRecord corresponding to that DeferUsage.
Expand Down

0 comments on commit 40f07e2

Please sign in to comment.