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. |
There was a problem hiding this comment.
@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.
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-newing 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.
I prefer being explicit and use new for classes. ES2015 seems to agree with me.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
I'd use isCacheEnabled, something more verbose & logical given the boolean variable value.
There was a problem hiding this comment.
How about just cacheEnabled?
|
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. |
Manual reimplementation of #349.
This moves Babel transforms to the main process, and caches the transpiled results.
It uses
caching-transformto 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-precompiledto 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.