optimize no-cycle rule using strongly connected components#2998
optimize no-cycle rule using strongly connected components#2998ljharb merged 1 commit intoimport-js:mainfrom
Conversation
…ErrorMessagePath` for faster error messages
This comment was marked as resolved.
This comment was marked as resolved.
|
👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎ This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored. |
|
Why is |
|
Good question. I think it's that this is the first new PR it's been run on since i installed it? |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2998 +/- ##
===========================================
+ Coverage 85.33% 95.91% +10.57%
===========================================
Files 78 79 +1
Lines 3300 3352 +52
Branches 1160 1171 +11
===========================================
+ Hits 2816 3215 +399
+ Misses 484 137 -347 ☔ View full report in Codecov by Sentry. |
ljharb
left a comment
There was a problem hiding this comment.
Looks great! I'll look at failing tests next
f64a123 to
a47b5b9
Compare
|
would love to see that optimization! |
|
Can't wait for this to be merged! |
|
@ljharb any news on this bro? |
a47b5b9 to
580c241
Compare
This comment was marked as resolved.
This comment was marked as resolved.
|
There's a pathology with SCC right now:
|
ljharb
left a comment
There was a problem hiding this comment.
I see two uncovered lines - can we add test cases to cover them?
Otherwise, this LGTM assuming all existing tests pass!
|
About the uncovered lines, I see them in codecov. The 1st is early return marked "no-self-import territory", so unrelated to my changes. The other is early return when files don't have the same SCC. |
|
After all these changes, I decided to measure performance impact. Without SCC (disableScc: true): 367 seconds (6:07 minutes) With SCC: 133 seconds (2:13 minutes) (I made sure it isn't using eslint cache) So we're talking about a 63% decrease in run time. |
|
Notice that we discovered performance downgrade at un-ts/eslint-plugin-import-x#113 when we ported this "optimization", I don't quite sure whether there were some improvements after we ported. cc @SukkaW |
Thanks, I have already seen this. What I did about it from when it was ported to the community fork:
In summary, this PR diverged significantly from the port discussed, in a way which should improve performance, invalidating prior benchmarks. A workaround has been built in to fall-back on in case of performance regression, without rolling-back. |
It was only after backporting the PR that I realized this was still an early experiment and a PoC. I'm considering using |
Lets make the
no-cyclerule faster by not running many unnecessary BFSes.For each dependency graph (aka
ExportMap) we can run Tarjan's SCC once (which is a derivative of DFS = O(n))That saves us a lot of work because we run a linear-complexity algorithm once, as opposed to for each linted file (which turned us O(n^2))
#2937