Skip to content

Commit 02c2a34

Browse files
Avoid unnecessary array copying in ConditionValidationState.advance() (#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.
1 parent acfe319 commit 02c2a34

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

.changeset/fast-points-wonder.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@apollo/federation-internals": patch
3+
"@apollo/gateway": patch
4+
"@apollo/composition": patch
5+
---
6+
7+
Reduce memory overhead during satisfiability checking when there are many options.

query-graphs-js/src/conditionsValidation.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ConditionValidationState {
2525
) {}
2626

2727
advance(supergraph: Schema): ConditionValidationState[] | null {
28-
let newOptions: SimultaneousPathsWithLazyIndirectPaths[] = [];
28+
const newOptions: SimultaneousPathsWithLazyIndirectPaths[] = [];
2929
for (const paths of this.subgraphOptions) {
3030
const pathsOptions = advanceSimultaneousPathsWithOperation(
3131
supergraph,
@@ -40,7 +40,7 @@ class ConditionValidationState {
4040
if (!pathsOptions) {
4141
continue;
4242
}
43-
newOptions = newOptions.concat(pathsOptions);
43+
newOptions.push(...pathsOptions);
4444
}
4545

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

0 commit comments

Comments
 (0)