Skip to content

perf(query-planner): reduce allocations and hash-based node comparison in query planner#9803

Open
tninesling wants to merge 6 commits into
devfrom
tninesling/planner-mem-opts
Open

perf(query-planner): reduce allocations and hash-based node comparison in query planner#9803
tninesling wants to merge 6 commits into
devfrom
tninesling/planner-mem-opts

Conversation

@tninesling

@tninesling tninesling commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Node comparisons:

  • When comparing potential merge candidate in can_merge_sibling_in, this change compares hashes of the nodes instead of a deep data comparison. Note that this does not affect the check for merging grandchild nodes, as that caused the planner to miss merge opportunities in a previous commit

Allocation savings:

  • Converts subgraph_and_merge_at_key from string formatting to numeric hash
  • .iter() instead of .clone().into_iter() on possible_types
  • .copied() instead of .cloned() on Copy-type NodeIndex
  • Move owned Vec instead of cloning in flat_wrap_nodes

Checklist

Complete the checklist (and note appropriate exceptions) before the PR is marked ready-for-review.

  • PR description explains the motivation for the change and relevant context for reviewing
  • PR description links appropriate GitHub/Jira tickets (creating when necessary)
  • Changeset is included for user-facing changes
  • Changes are compatible1
  • Documentation2 completed
  • Performance impact assessed and acceptable
  • Metrics and logs are added3 and documented
  • Tests added and passing4
    • Unit tests
    • Integration tests
    • Manual tests, as necessary

Exceptions

Note any exceptions here

Notes

Footnotes

  1. It may be appropriate to bring upcoming changes to the attention of other (impacted) groups. Please endeavour to do this before seeking PR approval. The mechanism for doing this will vary considerably, so use your judgement as to how and when to do this.

  2. Configuration is an important part of many changes. Where applicable please try to document configuration examples.

  3. A lot of (if not most) features benefit from built-in observability and debug-level logs. Please read this guidance on metrics best-practices.

  4. Tick whichever testing boxes are applicable. If you are adding Manual Tests, please document the manual testing (extensively) in the Exceptions.

…uery planner

Add a precomputed `merge_key_hash` (u64) on each node for fast-reject in
`can_merge_sibling_in` and `can_merge_grandchild_in`, avoiding deep
Vec<FetchDataPathElement> equality when hashes differ. Convert
`subgraph_and_merge_at_key` from string formatting to numeric hash.

Additional allocation savings:
- `.iter()` instead of `.clone().into_iter()` on `possible_types`
- `.copied()` instead of `.cloned()` on Copy-type NodeIndex
- Move owned Vec<PlanNode> instead of cloning in flat_wrap_nodes

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@tninesling
tninesling requested review from a team as code owners July 14, 2026 00:33
@apollo-librarian

apollo-librarian Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

✅ Docs preview has no changes

The preview was not built because there were no changes.

Build ID: f104ffe466ae96d5b02f0d72
Build Logs: View logs


✅ AI Style Review — No Changes Detected

No MDX files were changed in this pull request.

Review Log: View detailed log

This review is AI-generated. Please use common sense when accepting these suggestions, as they may not always be accurate or appropriate for your specific context.

@github-actions

Copy link
Copy Markdown
Contributor

@tninesling, please consider creating a changeset entry in /.changesets/. These instructions describe the process and tooling.

The merge key comparison was incorrect and could occasionally prevent
merging nodes
@tninesling tninesling changed the title perf(query-planner): reduce allocations and add hash fast-reject in query planner perf(query-planner): reduce allocations in query planner Jul 15, 2026
@tninesling tninesling changed the title perf(query-planner): reduce allocations in query planner perf(query-planner): reduce allocations and hash-based node comparison in query planner Jul 15, 2026
Comment thread apollo-federation/src/query_plan/fetch_dependency_graph.rs Outdated
Comment thread apollo-federation/src/query_plan/fetch_dependency_graph.rs Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants