From da27090d830d1591829dd38ff6a71352333958ba Mon Sep 17 00:00:00 2001 From: Christoph Pojer Date: Thu, 14 Jan 2016 13:47:31 -0800 Subject: [PATCH] Cache all module data Summary: We used to only cache the `dependencies` and `name` of a Module but we were actually accessing two more fields (async dependencies and the `isHaste` field) which meant we were always reading every single file from disk. In D2644383 I noticed that but realized that the Promise was cached, meaning we would read every file once *per instance* and I didn't think about cross-instance reads over time. My initial version added more caching (but also missed the `isHaste` field) but then I got rid of the cache call for `dependencies`. So my change from before didn't make anything worse but it also didn't make anything better. This change now caches everything until the contents of the file actually changes. public Reviewed By: martinbigio Differential Revision: D2831569 fb-gh-sync-id: 74081abc0ce3ca96b4e56c3c9b6d24aa84f7496c --- .../src/DependencyResolver/Module.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/react-packager/src/DependencyResolver/Module.js b/react-packager/src/DependencyResolver/Module.js index 3fcd63f0..f6eb72be 100644 --- a/react-packager/src/DependencyResolver/Module.js +++ b/react-packager/src/DependencyResolver/Module.js @@ -31,7 +31,11 @@ class Module { } isHaste() { - return this.read().then(data => !!data.id); + return this._cache.get( + this.path, + 'isHaste', + () => this.read().then(data => !!data.id) + ); } getName() { @@ -67,11 +71,19 @@ class Module { } getDependencies() { - return this.read().then(data => data.dependencies); + return this._cache.get( + this.path, + 'dependencies', + () => this.read().then(data => data.dependencies) + ); } getAsyncDependencies() { - return this.read().then(data => data.asyncDependencies); + return this._cache.get( + this.path, + 'asyncDependencies', + () => this.read().then(data => data.asyncDependencies) + ); } invalidate() {