Skip to content

Commit

Permalink
Avoid unnecessary array copying in `ConditionValidationState.advance(…
Browse files Browse the repository at this point in the history
…)` (#3109)

We were using `concat()` in `ConditionValidationState.advance()`, which
was frequently copying the array. Shifting this to use `push()` instead
increases performance significantly for some graphs.
  • Loading branch information
sachindshinde authored Aug 21, 2024
1 parent acfe319 commit 02c2a34
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .changeset/fast-points-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@apollo/federation-internals": patch
"@apollo/gateway": patch
"@apollo/composition": patch
---

Reduce memory overhead during satisfiability checking when there are many options.
4 changes: 2 additions & 2 deletions query-graphs-js/src/conditionsValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ConditionValidationState {
) {}

advance(supergraph: Schema): ConditionValidationState[] | null {
let newOptions: SimultaneousPathsWithLazyIndirectPaths[] = [];
const newOptions: SimultaneousPathsWithLazyIndirectPaths[] = [];
for (const paths of this.subgraphOptions) {
const pathsOptions = advanceSimultaneousPathsWithOperation(
supergraph,
Expand All @@ -40,7 +40,7 @@ class ConditionValidationState {
if (!pathsOptions) {
continue;
}
newOptions = newOptions.concat(pathsOptions);
newOptions.push(...pathsOptions);
}

// If we got no options, it means that particular selection of the conditions cannot be satisfied, so the
Expand Down

0 comments on commit 02c2a34

Please sign in to comment.