Skip to content

Optimize: Update transitive closure algorithm#920

Open
hneiva wants to merge 2 commits intomainfrom
hneiva/transitive-closure
Open

Optimize: Update transitive closure algorithm#920
hneiva wants to merge 2 commits intomainfrom
hneiva/transitive-closure

Conversation

@hneiva
Copy link
Contributor

@hneiva hneiva commented Mar 13, 2026

The previous implementation scanned all edges on every iteration of a fixed-point loop, resulting in O(depth * edges) complexity. For deep dependency chains this is catastrophic - a 5000-node chain required 5000 full passes over all edges.

Replace with a standard Breadth-First Search using an adjacency list built once upfront, reducing complexity to O(vertices + edges). Benchmarks on large graphs show 22x-1333x speedups depending on graph shape, with identical results verified against the original algorithm.

@codecov
Copy link

codecov bot commented Mar 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.18%. Comparing base (01028b2) to head (f19b24b).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #920      +/-   ##
==========================================
+ Coverage   77.14%   77.18%   +0.04%     
==========================================
  Files         130      130              
  Lines       11868    11883      +15     
  Branches     1458     1462       +4     
==========================================
+ Hits         9155     9172      +17     
+ Misses       2331     2330       -1     
+ Partials      382      381       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

The previous implementation scanned all edges on every iteration of a
fixed-point loop, resulting in O(depth * edges) complexity. For deep
dependency chains this is catastrophic - a 5000-node chain required
5000 full passes over all edges.

Replace with a standard Breadth-First Search using an adjacency list
built once upfront, reducing complexity to O(vertices + edges). Benchmarks
on large graphs show 22x-1333x speedups depending on graph shape, with
identical results verified against the original algorithm.
@hneiva hneiva force-pushed the hneiva/transitive-closure branch from 86d36d8 to 56fb085 Compare March 18, 2026 16:39
@hneiva hneiva marked this pull request as ready for review March 18, 2026 16:54
@hneiva hneiva requested a review from a team as a code owner March 18, 2026 16:54
@hneiva hneiva requested a review from ahal March 18, 2026 16:54
@bhearsum bhearsum changed the title Optimize: Update transitive closure algorythm. Optimize: Update transitive closure algorithm Mar 18, 2026
@bhearsum
Copy link
Contributor

If you haven't already, testing this with Gecko would be a good additional sanity check (eg: that it produces identical graphs, no exceptions, etc.).

@hneiva
Copy link
Contributor Author

hneiva commented Mar 18, 2026

If you haven't already, testing this with Gecko would be a good additional sanity check (eg: that it produces identical graphs, no exceptions, etc.).

I have tested this against gecko and found no diffs on the generated graphs.

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