Skip to content

Commit 684f89e

Browse files
committed
Improve caching size of computations
1 parent af3dc33 commit 684f89e

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

packages/app/src/sandbox/eval/manager.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -706,22 +706,33 @@ export default class Manager {
706706
Object.keys(this.transpiledModules[path].tModules).forEach(query => {
707707
const tModule = this.transpiledModules[path].tModules[query];
708708

709-
// Only save modules that are not precomputed
710-
if (tModule.module.requires == null) {
709+
if (
710+
!this.manifest.contents[tModule.module.path] ||
711+
(tModule.module.path.endsWith('.js') &&
712+
tModule.module.requires == null)
713+
) {
714+
// Only save modules that are not precomputed
711715
serializedTModules[tModule.getId()] = tModule.serialize();
712716
}
713717
});
714718
});
715719

716720
const dependenciesQuery = this.getDependencyQuery();
717721

722+
const meta = {};
723+
Object.keys(getCombinedMetas() || {}).forEach(p => {
724+
const dir = pathUtils.dirname(p.replace('/node_modules', ''));
725+
meta[dir] = meta[dir] || [];
726+
meta[dir].push(pathUtils.basename(p));
727+
});
728+
718729
return {
719730
transpiledModules: serializedTModules,
720731
cachedPaths: this.cachedPaths,
721732
version: SCRIPT_VERSION,
722733
timestamp: new Date().getTime(),
723734
configurations: this.configurations,
724-
meta: getCombinedMetas(),
735+
meta,
725736
dependenciesQuery,
726737
};
727738
}
@@ -767,7 +778,13 @@ export default class Manager {
767778
version === SCRIPT_VERSION &&
768779
dependenciesQuery === this.getDependencyQuery()
769780
) {
770-
setCombinedMetas(meta);
781+
const combinedMetas = {};
782+
Object.keys(meta).forEach(dir => {
783+
meta[dir].forEach(file => {
784+
combinedMetas[`/node_modules` + dir + '/' + file] = true;
785+
});
786+
});
787+
setCombinedMetas(combinedMetas);
771788

772789
this.cachedPaths = cachedPaths;
773790
this.configurations = configurations;
@@ -794,7 +811,8 @@ export default class Manager {
794811
}
795812
} catch (e) {
796813
if (process.env.NODE_ENV === 'development') {
797-
console.error(e);
814+
console.warn('Problems parsing cache');
815+
console.warn(e);
798816
}
799817
}
800818
this.clearCache();

packages/app/src/sandbox/eval/transpiled-module.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,10 @@ export default class TranspiledModule {
484484
* @param {*} manager
485485
*/
486486
async transpile(manager: Manager) {
487+
if (this.source) {
488+
return this;
489+
}
490+
487491
if (manager.transpileJobs[this.getId()]) {
488492
// Is already being transpiled
489493
return this;
@@ -492,10 +496,6 @@ export default class TranspiledModule {
492496
// eslint-disable-next-line
493497
manager.transpileJobs[this.getId()] = true;
494498

495-
if (this.source) {
496-
return this;
497-
}
498-
499499
this.hasMissingDependencies = false;
500500

501501
// Remove this module from the initiators of old deps, so we can populate a

0 commit comments

Comments
 (0)