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

Faster is acyclic test

Open vbraun opened this issue 4 years ago • 4 comments

This branch implements the fast acyclic test based on the depth first search. If there are cycles then the old algorithm is used, in particular the output stays the same.

In my project (5000+ webpack modules) this speeds up the circular dependency check from about 4300ms to 30ms (of course only if there are no cycles, if there are then nothing changes)

FIxes #65

vbraun avatar Jan 15 '21 18:01 vbraun

This should work great if a particular project enforces no cycles (e.g. via failOnError plugin setting, or via other measures). However, if it's not generally enforced, a project would tend to have one or two "well-known" circular dependencies. In this case the extra isAcyclic check before the actual cycles enumerating would probably add some overhead? I would assume it's somewhat negligible (given its O(N) complexity) - but any thoughts on that? @vbraun

amakhrov avatar Feb 08 '21 22:02 amakhrov

If the overhead is too great (not saying it necessarily is), looks like making the "passQuickly" optional would be reasonably easy?

  if (passQuickly && isAcyclic(graph))
    return;

Would be great to get this in - my team is concerned about adding this plugin because of performance (we'd have failOnError on, so would expect failure to be the unusual case).

lexanth avatar Feb 09 '21 12:02 lexanth

Well in my experience the overhead (in case of cycles present) is <1%, so I'd call than negligible.

If you have cycles that you are fine with then you really need a setting that somehow excludes that cycle from error reporting. Though I'd argue that your time would be much better spent breaking that cycle than figuring out how to configure webpack to allow a particular circular dependency.

vbraun avatar Feb 10 '21 18:02 vbraun

On webpack 5 this branch shows the following warning:

 [DEP_WEBPACK_DEPRECATION_ARRAY_TO_SET] DeprecationWarning: Compilation.modules was changed from Array to Set (using Array method 'filter' is deprecated)

Knagis avatar May 26 '21 19:05 Knagis