Conversation
When using `cacheDirectory=true`, the `findCacheDir` module is repeatedly called, and it does some synchronous filesystem calls under the hood. However, since `findCacheDir` is more or less a pure function, it's probably safe to call it only once during process lifetime.
Codecov Report
@@ Coverage Diff @@
## master #375 +/- ##
==========================================
+ Coverage 81.04% 81.87% +0.82%
==========================================
Files 6 6
Lines 153 160 +7
Branches 33 35 +2
==========================================
+ Hits 124 131 +7
Misses 13 13
Partials 16 16
Continue to review full report at Codecov.
|
src/resolve-rc.js
Outdated
| } | ||
|
|
||
| return find(loc, rel); | ||
| return (cache[cacheKey] = find(loc, rel)); |
There was a problem hiding this comment.
For readability here can you use a template string and reverse the logic?
if (!cacheKey in cache) {
cache[cacheKey] = ...
}
return cache[cacheKey];
There was a problem hiding this comment.
Done deal. I wasn't sure whether template strings were allowed by the local code style. :)
|
Thanks, that looks all awesome. Did you check if the build gets faster with this? |
|
I measured things a little (somewhat unscientifically, of course, since this is on my MBP and there's other IO and processing noise). The "babel-core" patch mentioned is babel/babel#5292 . The TL;DR is "yes, it does have an effect 😸 " Performance measurements
Sync IO tracesOutput summarized by https://github.com/akx/summarize-sync-io All stockPatched babel-loaderPatched babel-loader and babel-core |
|
Thank you |
* Instantiate default cache directory lazily, and only once When using `cacheDirectory=true`, the `findCacheDir` module is repeatedly called, and it does some synchronous filesystem calls under the hood. However, since `findCacheDir` is more or less a pure function, it's probably safe to call it only once during process lifetime. * Cache resolve-rc results
While tracking down the reason for some build slowness with
--trace-sync-io, I found a couple file system hotspots that could use some caching.cacheDirectory=true,findCacheDiris repeatedly called, and it does some synchronous calls under the hood. HoweverfindCacheDiris more or less a pure function, so it's probably safe to call it once during process lifetime.resolve-rchas some caches for singleexistsandreadoperations, but there's still some more time that can be shaved off by simply memoizing the entireresolve-rcfunction.These should not be breaking changes, unless
.babelrcfiles are created in intermediate directories during process lifetime, which sounds very unlikely.