-
-
Notifications
You must be signed in to change notification settings - Fork 451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FS caching improvements #375
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 stock
Patched babel-loader
Patched 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
,findCacheDir
is repeatedly called, and it does some synchronous calls under the hood. HoweverfindCacheDir
is more or less a pure function, so it's probably safe to call it once during process lifetime.resolve-rc
has some caches for singleexists
andread
operations, but there's still some more time that can be shaved off by simply memoizing the entireresolve-rc
function.These should not be breaking changes, unless
.babelrc
files are created in intermediate directories during process lifetime, which sounds very unlikely.