Skip to content

Optimize: Update transitive closure algorithm#920

Open
hneiva wants to merge 2 commits into
mainfrom
hneiva/transitive-closure
Open

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

Conversation

@hneiva

@hneiva hneiva commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

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

codecov Bot commented Mar 13, 2026

Copy link
Copy Markdown

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
Copy Markdown
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

hneiva commented Mar 18, 2026

Copy link
Copy Markdown
Contributor Author

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.

@bhearsum bhearsum 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.

I'm -0 on this...it adds complexity for no real world win. As long as it doesn't hurt perf in our real world cases I guess it's fine to take.

@ahal ahal left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Seems fine to me. It's a few more lines of code, but I can't really say it's much more complex than the old algorithm

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.

3 participants