Skip to content

Commit

Permalink
memoize existsSync calls on the fastboot instance itself
Browse files Browse the repository at this point in the history
In large applications with many nested addons and engines, this can do
excessive work.

Luckily it is perfectly consistent for us to cache this on the addon
instance state. In-fact it is incoherent for this to change from the
perspective of one fastboot addon instance
  • Loading branch information
stefanpenner committed Mar 2, 2019
1 parent d688533 commit aac6fe5
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ module.exports = {

init() {
this._super.init && this._super.init.apply(this, arguments);
this._existsCache = new Map();
},

existsSync(path) {
if (this._existsCache.has(path)) {
return this._existsCache.get(path);
}

const exists = existsSync(path);

this._existsCache.set(path, exists);
return exists;
},

/**
Expand Down Expand Up @@ -139,7 +151,7 @@ module.exports = {
const currentAddonFastbootPath = path.join(addon.root, 'fastboot');

let fastbootTree;
if (existsSync(currentAddonFastbootPath)) {
if (this.existsSync(currentAddonFastbootPath)) {
fastbootTree = this.treeGenerator(currentAddonFastbootPath);
}

Expand Down Expand Up @@ -168,7 +180,7 @@ module.exports = {

// check the parent containing the fastboot directory
const projectFastbootPath = path.join(this.project.root, 'fastboot');
if (existsSync(projectFastbootPath)) {
if (this.existsSync(projectFastbootPath)) {
let fastbootTree = this.treeGenerator(projectFastbootPath);
fastbootTrees.push(fastbootTree);
}
Expand Down

0 comments on commit aac6fe5

Please sign in to comment.