packager: preprocess outdated dependencies

Summary:
Note: if this changeset causes some breakage, consider disabling rather than reverting. To disable, the call to `_preprocessPotentialDependencies` in `ResolutionRequest` can be removed.

It's a bit of an experiment. I couldn't see any particular regression caused by this, but I could see net improvement of the global cache performance, as it unlock much, much stronger batching: indeed, instead of discovering dependencies progressively, we synchronously figure out the list of all potential modules of a bundle, and kick-off cache fetching and/or transformations. So when it comes to fetching from the global cache, it'll do less requests, and each requests will ask for considerably more keys at a time.

Potential problem caused by this changeset: if a module's dependencies completely changed, then the first time we try to build the bundle it'll start transforming modules that we probably don't care at all anymore, spending precious CPU time for nothing. I've been thinking about it and I cannot see such a case happening much often. Even if it happens, it should not cause any bug or corruption, it would just take additional time.

Other potential problem: that this new code doesn't handle some types of edge cases. It's quite hard to figure out what could possibly break in the `ResolutionRequest` code (and I think it would benefit from a larger refactor). We do have a good test coverage for `DependencyGraph` and it seems to work smoothly, so I'm relatively confident we're not breaking edge cases.

Reviewed By: davidaurelio

Differential Revision: D4875467

fbshipit-source-id: 2dfcc755bec638d3d1c47862ec1de5220953e812
This commit is contained in:
Jean Lauliac
2017-04-13 10:31:30 -07:00
committed by Facebook Github Bot
parent 33749c2714
commit 219328d000
9 changed files with 159 additions and 45 deletions
@@ -11,6 +11,7 @@
'use strict';
import type {CachedReadResult, ReadResult} from '../../node-haste/Module';
import type {TransformedFile} from '../types.flow';
import type {ModuleCache} from './node-haste.flow';
@@ -33,6 +34,14 @@ module.exports = class Module {
this.type = 'Module';
}
readCached(): CachedReadResult {
throw new Error('not implemented');
}
readFresh(): Promise<ReadResult> {
return Promise.reject(new Error('not implemented'));
}
getName() {
return this.name;
}
@@ -63,6 +63,8 @@ const nullModule = {
hash() {
throw new Error('not implemented');
},
readCached() { throw new Error('not implemented'); },
readFresh() { return Promise.reject(new Error('not implemented')); },
};
exports.createResolveFn = function(options: ResolveOptions): ResolveFn {