Skip to content

Commit f1db531

Browse files
soryy708ljharb
authored andcommitted
[Performance] no-cycle: dont scc for each linted file
1 parent 5c9757c commit f1db531

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
1616

1717
### Changed
1818
- [Docs] [`no-relative-packages`]: fix typo ([#3066], thanks [@joshuaobrien])
19+
- [Performance] [`no-cycle`]: dont scc for each linted file ([#3068], thanks [@soryy708])
1920

2021
## [2.30.0] - 2024-09-02
2122

@@ -1140,6 +1141,7 @@ for info on changes for earlier releases.
11401141

11411142
[`memo-parser`]: ./memo-parser/README.md
11421143

1144+
[#3068]: https://github.com/import-js/eslint-plugin-import/pull/3068
11431145
[#3066]: https://github.com/import-js/eslint-plugin-import/pull/3066
11441146
[#3065]: https://github.com/import-js/eslint-plugin-import/pull/3065
11451147
[#3052]: https://github.com/import-js/eslint-plugin-import/pull/3052

src/scc.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,18 @@ export default class StronglyConnectedComponentsBuilder {
1818
}
1919

2020
static for(context) {
21-
const cacheKey = context.cacheKey || hashObject(context).digest('hex');
21+
const settingsHash = hashObject({
22+
settings: context.settings,
23+
parserOptions: context.parserOptions,
24+
parserPath: context.parserPath,
25+
}).digest('hex');
26+
const cacheKey = context.path + settingsHash;
2227
if (cache.has(cacheKey)) {
2328
return cache.get(cacheKey);
2429
}
2530
const scc = StronglyConnectedComponentsBuilder.calculate(context);
26-
cache.set(cacheKey, scc);
31+
const visitedFiles = Object.keys(scc);
32+
visitedFiles.forEach((filePath) => cache.set(filePath + settingsHash, scc));
2733
return scc;
2834
}
2935

0 commit comments

Comments
 (0)