Skip to content

[Fusion] Let Apollo Federation lookups reuse entities instead of waiting for a third fetch wave - #10791

Merged
michaelstaib merged 3 commits into
ChilliCream:mainfrom
michaelstaib:perf/apollo-entity-reuse
Nov 13, 2026
Merged

michaelstaib merged 3 commits into
ChilliCream:mainfrom
michaelstaib:perf/apollo-entity-reuse

Conversation

@michaelstaib

Copy link
Copy Markdown
Member

On Apollo Federation subgraphs, the planner folded identical entity lookups at different depths into the deeper one. So the inventory lookup for topProducts waited for the nested product lookups and ran as a third fetch wave, about 4 ms per request in constant-latency mode. When entity reuse can serve the deeper lookup, the lookups now stay apart and the deeper one runs after the shallower one, which is what composite lookups already do. The nested lookup is then served from entities already in the result, so the Apollo gateway is within 1-2% of the composite gateway. Apollo nodes now write these ordering dependencies to the plan JSON and the parser restores them, using the existing dependencies property, so the plan format is unchanged.

Metric Before Optimization After Optimization
Constant-latency req/s, AOT 2,672 3,248 (+21.6%)
Constant-latency p50 / p95, AOT 17.13 / 21.88 ms 14.13 / 19.77 ms
Constant-latency req/s, JIT 2,682 3,298 (+23.0%)
Constant-latency p50 / p95, JIT 17.03 / 22.13 ms 13.94 / 19.57 ms
Constant req/s, AOT 4,561 4,711 (+3.3%)
Constant req/s, JIT 4,788 4,863 (+1.6%)
Gateway CPU per request, AOT / JIT 0.841 / 0.712 ms 0.774 / 0.667 ms
Subgraph CPU per request, AOT / JIT 1.849 / 1.804 ms 1.679 / 1.640 ms
Min latency (constant-latency), AOT / JIT 12.29 / 11.88 ms 8.50 / 8.23 ms
Avg RSS (constant-latency), AOT / JIT 101.2 / 171.8 MB 97.0 / 167.1 MB
Avg RSS (constant), AOT / JIT 105.3 / 164.6 MB 92.5 / 162.9 MB

Measured on a local copy of the benchmark (fusion-fed deep query, k6 with 50 VUs on pinned CPUs, inline socket settings, 4 ms subgraph delay in constant-latency mode, mean of two alternating 30 s rounds; CPU and min-latency rows are from constant-latency runs, and the composite gateway reaches 3,309 AOT and 3,324 JIT constant-latency req/s on the same machine).

OperationPlanner.Version is bumped from 2.7.0 to 2.8.0, because affected Apollo plans now have a different shape.

…ing for a third fetch wave

Identical Apollo entity lookups at different depths were folded into the
deeper lookup, so a shallow lookup such as inventory for `topProducts`
waited for nested lookups and ran as an extra fetch wave. When entity
reuse can serve the deeper lookup, the lookups now stay apart and the
deeper one runs after the shallower one, as composite lookups already do.

Apollo nodes now write their ordering dependencies to the plan JSON and
the parser restores them. Bumps OperationPlanner.Version to 2.8.0.
Copilot AI balanced review requested due to automatic review settings November 3, 2026 18:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The round-trip test lacks coverage for batched or same-depth merged Apollo lookups with cross-batch dependencies, leaving optional ordering dependencies and required data prerequisites unverified.

1 open issue
What changed in this PR

This PR extends Fusion’s entity-reuse planning to Apollo Federation lookups, keeping reusable lookups at different depths separate to avoid an extra fetch wave.

Changes:

  • Adds ordering dependencies between reusable Apollo lookups.
  • Preserves those dependencies during plan JSON serialization and parsing without adding a new JSON property.
  • Adds planning and round-trip tests, and disables reuse splitting in existing merge-policy tests.
File Description
src/​HotChocolate/​Fusion/​test/​Fusion.Execution.Tests/​Planning/​ApolloLookupMergePlanningTests.cs Disables reuse splitting to isolate existing merge behavior.
src/​HotChocolate/​Fusion/​test/​Fusion.Execution.Tests/​Planning/​ApolloEntityReuseSplittingTests.cs Tests lookup separation, dependency round-tripping, and disabled splitting.
src/​HotChocolate/​Fusion/​src/​Fusion.Execution/​Planning/​OperationPlanner.BuildExecutionTree.cs Separates reusable Apollo lookups and classifies ordering dependencies.
src/​HotChocolate/​Fusion/​src/​Fusion.Execution/​Execution/​Results/​EntityReuseCandidateMap.cs Includes optional Apollo dependencies in reuse candidate discovery.
src/​HotChocolate/​Fusion/​src/​Fusion.Execution/​Execution/​Nodes/​Serialization/​JsonOperationPlanParser.cs Restores optional ordering dependencies for Apollo batch members.
src/​HotChocolate/​Fusion/​src/​Fusion.Execution/​Execution/​Nodes/​Serialization/​JsonOperationPlanFormatter.cs Writes Apollo ordering dependencies into the existing dependency arrays.

Review effort: Balanced

Comment on lines +560 to +564
|| (groupNode is ApolloOperationBatchExecutionNode apolloGroup
&& OperationPlanner.IsEntityReuseOrderingDependency(
apolloGroup,
memberIndex,
depNode,
@michaelstaib
michaelstaib merged commit 01d35f5 into ChilliCream:main Nov 13, 2026
12 of 13 checks passed
This was referenced Nov 17, 2026
This was referenced Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants