Skip to content

perf(query-planner): replace DFS transitive reduction with petgraph algo#9804

Open
tninesling wants to merge 2 commits into
devfrom
tninesling/planner-tred-opt
Open

perf(query-planner): replace DFS transitive reduction with petgraph algo#9804
tninesling wants to merge 2 commits into
devfrom
tninesling/planner-tred-opt

Conversation

@tninesling

@tninesling tninesling commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Replace the O(V*E) DFS-from-every-node reduce() with petgraph's dag_transitive_reduction_closure (Habib-Morvan-Rampon algorithm).

The StableDiGraph-to-AdjList conversion is extracted into to_toposorted_adjacency_list, which maps sparse stable node indices to dense toposort-ordered indices for the reduction algorithm. Redundant edges are identified by querying the reduction graph directly rather than materializing an intermediate adjacency matrix.

All existing call sites, operation order, and defer-edge recording behavior are preserved — this is a pure algorithm swap.


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.

Replace the O(V*E) DFS-from-every-node `reduce()` with petgraph's
`dag_transitive_reduction_closure` (Habib-Morvan-Rampon algorithm).

The StableDiGraph-to-AdjList conversion is extracted into
`to_toposorted_adjacency_list`, which maps sparse stable node indices
to dense toposort-ordered indices for the reduction algorithm.
Redundant edges are identified by querying the reduction graph
directly rather than materializing an intermediate adjacency matrix.

All existing call sites, operation order, and defer-edge recording
behavior are preserved — this is a pure algorithm swap.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@tninesling
tninesling requested review from a team as code owners July 14, 2026 01:21
@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: 0e87dd75c215ce54c89a19c8
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.

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.

1 participant