eslint-plugin-import-x: [3.0.1] Huge performance regression in import/no-cycle
Hi. Today I upgraded the plugin to version 3.0.1 and noticed a huge drop in performance in the no-cycle rule. Details below.
Setup
Depencecies:
{
"eslint": "^9.6.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "npm:eslint-plugin-import-x@^3.0.1",
"eslint-plugin-import-x": "^3.0.1",
"typescript": "^5.5.3",
"typescript-eslint": "^8.0.0-alpha.39"
}
Eslint config, I only left the no-cycle rule
import importX from 'eslint-plugin-import-x';
import tseslint from 'typescript-eslint';
export default [
{
languageOptions: {
parser: tseslint.parser,
sourceType: 'module',
},
},
{
files: ['**/*.ts'],
plugins: {
'import-x': importX,
},
settings: {
...importX.configs.typescript.settings,
'import-x/resolver': {
typescript: {},
},
},
rules: {
'import-x/no-cycle': ['error', { maxDepth: 3 }],
},
},
];
I ran the test on these two machines.
macOS
System:
OS: macOS 13.6.7
CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
Memory: 5.96 GB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.4.0 - /usr/local/bin/node
npm: 10.8.1 - /usr/local/bin/npm
pnpm: 9.5.0 - /usr/local/bin/pnpm
Windows
System:
OS: Windows 10 10.0.19045
CPU: (4) x64 Intel(R) Core(TM) i5-4690K CPU @ 3.50GHz
Memory: 2.80 GB / 7.94 GB
Binaries:
Node: 22.4.1 - C:\Program Files\nodejs\node.EXE
npm: 10.8.2 - C:\Program Files\nodejs\npm.CMD
pnpm: 9.5.0 - C:\Program Files\nodejs\pnpm.CMD
Results:
MacOS:
eslint-plugin-import-x@0.5.3
Rule | Time (ms) | Relative
:-----------------|----------:|--------:
import-x/no-cycle | 8580.409 | 100.0%
Rule | Time (ms) | Relative
:-----------------|----------:|--------:
import-x/no-cycle | 8101.124 | 100.0%
Rule | Time (ms) | Relative
:-----------------|----------:|--------:
import-x/no-cycle | 8239.801 | 100.0%
eslint-plugin-import-x@3.0.1
Rule | Time (ms) | Relative
:-----------------|----------:|--------:
import-x/no-cycle | 25850.526 | 100.0%
Rule | Time (ms) | Relative
:-----------------|----------:|--------:
import-x/no-cycle | 24692.786 | 100.0%
Rule | Time (ms) | Relative
:-----------------|----------:|--------:
import-x/no-cycle | 26082.004 | 100.0%
Windows:
eslint-plugin-import-x@0.5.3
Rule | Time (ms) | Relative
:-----------------|----------:|--------:
import-x/no-cycle | 20999.926 | 100.0%
Rule | Time (ms) | Relative
:-----------------|----------:|--------:
import-x/no-cycle | 19591.972 | 100.0%
Rule | Time (ms) | Relative
:-----------------|----------:|--------:
import-x/no-cycle | 19811.106 | 100.0%
eslint-plugin-import-x@3.0.1
Rule | Time (ms) | Relative
:-----------------|----------:|--------:
import-x/no-cycle | 78557.409 | 100.0%
Rule | Time (ms) | Relative
:-----------------|----------:|--------:
import-x/no-cycle | 82919.007 | 100.0%
Rule | Time (ms) | Relative
:-----------------|----------:|--------:
import-x/no-cycle | 78773.430 | 100.0%
Summary
So these are the numbers. I ran the test on a fairly large TS codebase (~680 files). You can see that 3.0.1 is at least 3x slower on both machines, which is strange because this release was supposed to significantly improve no-cycle performance. What is also noteworthy to me are the test times on Windows compared to macOS with eslint-plugin-import-x@0.5.3 , they’re like ~2.5 times slower. I know both my pc’s are old and rather slow, but Windows have slightly better cpu, it’s also overclocked, so I don’t understand why it’s so slow there. But the times with eslint-plugin-import-x@3.0.1 on Windows are really bad, which worries me the most. I would appreciate your help with this issue and let me know if you need more info from me.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 7
- Comments: 26 (11 by maintainers)
@sqal @zloirock I’ve reverted #111 and I am currently working on creating a new rule
no-cycle-nextusing graph.Yes I will. Haven’t gotten around to it yet, but it’s on my list 😉.
We can’t backport https://github.com/import-js/eslint-plugin-import/pull/2998. It actually introduces an extra step (SCC doesn’t replace the original detection algorithm, instead it is a new additional check) without introducing a proper early return. That’s why it becomes slower and I have reverted it.
I am interested in using https://www.npmjs.com/package/@newdash/graphlib to implement a dependency graph, this should be faster than the
no-cyclecurrent hand-made implementation.core-jsrepo, config,no-cyclefrom 0.5.3 on my laptop takes 2937.782ms, from 3.0.1 - 4865.651ms. Without custom resolvers.I cloned the repository and built the plugin and can confirm that https://github.com/un-ts/eslint-plugin-import-x/commit/5cce9461c2863c31af126afb7c59d67deb13a6e7 is the commit that slowed down this rule. With https://github.com/un-ts/eslint-plugin-import-x/commit/fe3121a2d74db1c2178d1ab189ef59b80c5b90c4 it was working fine.
It means there must be some regression related to resolving and parsing. I will be looking into this!
In the meantime, there is a resolver made by @9romise: https://github.com/9romise/eslint-import-resolver-oxc