Repository navigation
module: avoid reparsing package.json in esm format detection - #66982
Conversation
Determining the format of a `.js` or `.ts` module called `getPackageScopeConfig()`, which spread the deserialized package configuration and thereby invoked its lazy `exports` and `imports` getters. Every resolved module parsed those maps again, so load time and memory grew with the number of modules in a package times the size of its `exports` map. Use `getPackageType()` for format detection and only look up the package.json path when warning about a typeless package. Stop spreading the configuration in `getPackageScopeConfig()` so that the maps are parsed only when accessed. Fixes: nodejs#66485 Signed-off-by: Gürgün Dayıoğlu <hey@gurgun.day>
|
Review requested:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #66982 +/- ##
==========================================
- Coverage 92.93% 90.59% -2.35%
==========================================
Files 428 797 +369
Lines 195236 278301 +83065
Branches 30176 53520 +23344
==========================================
+ Hits 181442 252115 +70673
- Misses 13467 16556 +3089
- Partials 327 9630 +9303
🚀 New features to boost your workflow:
|
|
This seems good, but needs nonzero tests. |
|
Landed in 45df6b7 |
Determining the format of a `.js` or `.ts` module called `getPackageScopeConfig()`, which spread the deserialized package configuration and thereby invoked its lazy `exports` and `imports` getters. Every resolved module parsed those maps again, so load time and memory grew with the number of modules in a package times the size of its `exports` map. Use `getPackageType()` for format detection and only look up the package.json path when warning about a typeless package. Stop spreading the configuration in `getPackageScopeConfig()` so that the maps are parsed only when accessed. Fixes: #66485 Signed-off-by: Gürgün Dayıoğlu <hey@gurgun.day> PR-URL: #66982 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Determining the format of a `.js` or `.ts` module called `getPackageScopeConfig()`, which spread the deserialized package configuration and thereby invoked its lazy `exports` and `imports` getters. Every resolved module parsed those maps again, so load time and memory grew with the number of modules in a package times the size of its `exports` map. Use `getPackageType()` for format detection and only look up the package.json path when warning about a typeless package. Stop spreading the configuration in `getPackageScopeConfig()` so that the maps are parsed only when accessed. Fixes: #66485 Signed-off-by: Gürgün Dayıoğlu <hey@gurgun.day> PR-URL: #66982 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
|
Thanks for fixing this! Could it be backported to v26.x and v24.x? It has a big effect on test runners that start a fresh process per test file. With date-fns 4.4.0 (864 files, 741 Under Vitest's default pool (a new process per test file), that cost is paid once per file. On our 500-file suite, Vitest takes ~78 s locally against ~7 s for Jest. |
Determining the format of a
.jsor.tsmodule callsgetPackageScopeConfig(), which spreads the deserialized package configuration and therefore invokes its lazyexportsandimportsgettersEvery resolved module parses those maps again so load time and memory grows with the number of modules in a package times the size of its
exportsmapInstead of crating yet another cache, use
getPackageType()for format detection and only look up the package.json path when warning about a typeless package91c4436Both date-fns and drizzle-orm are affected by this and should improve the same way
Supersedes #65812 and fixes #66485