Skip to content

Commit

Permalink
[Performance] no-cycle: dont scc for each linted file
Browse files Browse the repository at this point in the history
  • Loading branch information
soryy708 authored and ljharb committed Sep 23, 2024
1 parent 5c9757c commit f1db531
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange

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

## [2.30.0] - 2024-09-02

Expand Down Expand Up @@ -1140,6 +1141,7 @@ for info on changes for earlier releases.

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

[#3068]: https://github.com/import-js/eslint-plugin-import/pull/3068
[#3066]: https://github.com/import-js/eslint-plugin-import/pull/3066
[#3065]: https://github.com/import-js/eslint-plugin-import/pull/3065
[#3052]: https://github.com/import-js/eslint-plugin-import/pull/3052
Expand Down
10 changes: 8 additions & 2 deletions src/scc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ export default class StronglyConnectedComponentsBuilder {
}

static for(context) {
const cacheKey = context.cacheKey || hashObject(context).digest('hex');
const settingsHash = hashObject({
settings: context.settings,
parserOptions: context.parserOptions,
parserPath: context.parserPath,
}).digest('hex');
const cacheKey = context.path + settingsHash;
if (cache.has(cacheKey)) {
return cache.get(cacheKey);
}
const scc = StronglyConnectedComponentsBuilder.calculate(context);
cache.set(cacheKey, scc);
const visitedFiles = Object.keys(scc);
visitedFiles.forEach((filePath) => cache.set(filePath + settingsHash, scc));
return scc;
}

Expand Down

0 comments on commit f1db531

Please sign in to comment.