circular-dependency-plugin icon indicating copy to clipboard operation
circular-dependency-plugin copied to clipboard

Replace cycle detection algorithm with Tarjan's strongly connected components algorithm

Open hedgepigdaniel opened this issue 4 years ago • 5 comments

I noticed that this plugin was taking significant time (almost a second for a 5500 module project) to check for cycles in hot rebuilds. Tarjan's strongly connected components algorithm as I understand is the fastest way to find dependency cycles. Its running time is linear in the number of vertices (modules) + edges (dependencies).

My best guess is that the existing algorithm is quadratic in the number of modules, because for each module in the compilation, all its dependencies are traversed recursively, which in the worst case also visits each module in the compilation.

I haven't done benchmarks, but in the same project after this change, this plugin is no longer perceptible in the ProgressPlugin output.

I also changed the output:

  • One cycle is output only once, not separately for each file it contains
  • For cycles when some modules in the cycle are excluded - it now outputs all modules in the cycle even if some are excluded. This makes more sense IMO, since otherwise it prints e.g. a.js -> b.js even if a.js does not directly import b.js, which is confusing. If all modules in a cycle are excluded, no warning is generated (I added a test to enforce this)

hedgepigdaniel avatar Sep 19 '19 11:09 hedgepigdaniel

Thanks for sending this, I appreciate the effort that went into this. Since this reworks a lot of the core functionality I'll have to spend some time reviewing it, and I probably won't get to it until the weekend, I'll try to do a thorough review as soon as I can.

aackerman avatar Sep 19 '19 12:09 aackerman

This is a great contribution. Wish we had it merged.

sepehr avatar Jun 10 '20 22:06 sepehr

Was it benchmarked maybe?

TeoTN avatar Sep 22 '20 17:09 TeoTN

Any update on that? I would so appreciate any improvements to the plugin performance.

amakhrov avatar Feb 08 '21 22:02 amakhrov

Is there any hope for this improvement?

alfaproject avatar Jan 10 '23 20:01 alfaproject