diff --git a/CHANGELOG.md b/CHANGELOG.md index 01ab3f081..bbfaa0fb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange ### Fixed - [`no-duplicates`]: remove duplicate identifiers in duplicate imports ([#2577], thanks [@joe-matsec]) - [`consistent-type-specifier-style`]: fix accidental removal of comma in certain cases ([#2754], thanks [@bradzacher]) +- [Perf] `ExportMap`: Improve `ExportMap.for` performance on larger codebases ([#2756], thanks [@leipert]) ### Changed - [Docs] [`no-duplicates`]: fix example schema ([#2684], thanks [@simmo]) @@ -1066,6 +1067,7 @@ for info on changes for earlier releases. [`memo-parser`]: ./memo-parser/README.md +[#2756]: https://github.com/import-js/eslint-plugin-import/pull/2756 [#2754]: https://github.com/import-js/eslint-plugin-import/pull/2754 [#2748]: https://github.com/import-js/eslint-plugin-import/pull/2748 [#2699]: https://github.com/import-js/eslint-plugin-import/pull/2699 @@ -1737,6 +1739,7 @@ for info on changes for earlier releases. [@kylemh]: https://github.com/kylemh [@laysent]: https://github.com/laysent [@le0nik]: https://github.com/le0nik +[@leipert]: https://github.com/leipert [@lemonmade]: https://github.com/lemonmade [@lencioni]: https://github.com/lencioni [@leonardodino]: https://github.com/leonardodino diff --git a/src/ExportMap.js b/src/ExportMap.js index 7b8c88314..d31375c83 100644 --- a/src/ExportMap.js +++ b/src/ExportMap.js @@ -305,7 +305,7 @@ ExportMap.get = function (source, context) { ExportMap.for = function (context) { const { path } = context; - const cacheKey = hashObject(context).digest('hex'); + const cacheKey = context.cacheKey || hashObject(context).digest('hex'); let exportMap = exportCache.get(cacheKey); // return cached ignore @@ -559,7 +559,7 @@ ExportMap.parse = function (path, content, context) { if (tsConfigInfo.tsConfigPath !== undefined) { // Projects not using TypeScript won't have `typescript` installed. if (!ts) { ts = require('typescript'); } // eslint-disable-line import/no-extraneous-dependencies - + const configFile = ts.readConfigFile(tsConfigInfo.tsConfigPath, ts.sys.readFile); return ts.parseJsonConfigFileContent( configFile.config, @@ -781,12 +781,29 @@ export function recursivePatternCapture(pattern, callback) { } } +let parserOptionsHash = ''; +let prevParserOptions = ''; +let settingsHash = ''; +let prevSettings = ''; /** * don't hold full context object in memory, just grab what we need. + * also calculate a cacheKey, where parts of the cacheKey hash are memoized */ function childContext(path, context) { const { settings, parserOptions, parserPath } = context; + + if (JSON.stringify(settings) !== prevSettings) { + settingsHash = hashObject({ settings }).digest('hex'); + prevSettings = JSON.stringify(settings); + } + + if (JSON.stringify(parserOptions) !== prevParserOptions) { + parserOptionsHash = hashObject({ parserOptions }).digest('hex'); + prevParserOptions = JSON.stringify(parserOptions); + } + return { + cacheKey: String(parserPath) + parserOptionsHash + settingsHash + String(path), settings, parserOptions, parserPath,