-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Transpile in main thread #390
Transpile in main thread #390
Conversation
Using master - first run (no cache)
master - second run (with cache)
this branch - first run (no cache)
this branch - second run (w /cache)
Huge advantage when the cache is empty. |
@sindresorhus, @vdemedes, et al. - ready for review. |
|
||
function CachingPrecompiler(cacheDir) { | ||
if (!(this instanceof CachingPrecompiler)) { | ||
throw new Error('CachingPrecompiler must be called with new'); |
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.
@jamestalmage: What we do everywhere else is just invoke ourself with new
and return it. Maybe switch to that?:
if (!(this instanceof CachingPrecompiler)) {
return new CachingPrecompiler(cacheDir);
}
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.
Yeah sure. Probably worth matching style.
That said, after doing it the way you suggest for a long time, I am starting to think it's a mistake. ES2015 classes throw when function called, so magic auto-new
ing is not future proof. Also, it introduces an easy to overlook failure point when refactoring the function signature. I know I have forgotten to update that statement inside the if condition before.
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.
I prefer being explicit and use new
for classes. ES2015 seems to agree with me.
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.
OK, changed it back to the original behavior (throw if they forget to use new).
@jamestalmage: Looks pretty good, expect for the few things I mentioned. Also, it looks like there aren't very many tests on the |
filename: filename, | ||
sourceMaps: true, | ||
ast: false, | ||
inputSourceMap: sourceMap && sourceMap.toObject() |
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.
Make sure to include the babelrc: false
thing here.
Woo, nice improvement on cold start! 👍 Generally looks good to me. Could use a test though. @vdemedes ? |
Yeah. How far do you want me to take it? For This is what I am thinking for tests:
|
I don't think we should run all tests with and without. Just need some integration tests to ensure it's working correctly. What you've proposed sounds fine. |
785c6c8
to
8bc8387
Compare
@@ -137,6 +144,11 @@ Api.prototype.run = function () { | |||
return Promise.reject(new AvaError('Couldn\'t find any files to test')); | |||
} | |||
|
|||
var cache = self.options.cache !== false; |
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.
I'd use isCacheEnabled
, something more verbose & logical given the boolean variable value.
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.
How about just cacheEnabled
?
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.
Or that, yeah
I really dig the perf improvement! I commented on a few things, but never mind. We can do a cleanup later, I'd rather have this PR merged ASAP. |
Squashed commits: transpile in the main thread drop unused dependencies incorporate PR feedback add tests add unit tests
8bc8387
to
614eb12
Compare
OK, Incorporated the last round of feedback from @vdemedes. Once CI passes again, I intend to merge. |
Landed. |
Manual reimplementation of #349.
This moves Babel transforms to the main process, and caches the transpiled results.
It uses
caching-transform
to provide caching. Expensive requires (like babel) are placed inside the factory function, which caching-transform only calls when it determines it needs to transform a file.The path to each precompiled test is passed in the options object to fork:
It uses
require-precompiled
to install a require hook that pulls the transformed file from the cache.The caching directory is used by the users
package.json
, and installing innode_modules/.cache/ava
.If the cache directory cannot be found (i.e. if they have no package.json), or the user provides a --no-cache flag, pre-compilation still happens on the main thread - but results are published to a temp directory.