Skip to content

Commit aac6fe5

Browse files
committed
memoize existsSync calls on the fastboot instance itself
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
1 parent d688533 commit aac6fe5

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

index.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ module.exports = {
3939

4040
init() {
4141
this._super.init && this._super.init.apply(this, arguments);
42+
this._existsCache = new Map();
43+
},
44+
45+
existsSync(path) {
46+
if (this._existsCache.has(path)) {
47+
return this._existsCache.get(path);
48+
}
49+
50+
const exists = existsSync(path);
51+
52+
this._existsCache.set(path, exists);
53+
return exists;
4254
},
4355

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

141153
let fastbootTree;
142-
if (existsSync(currentAddonFastbootPath)) {
154+
if (this.existsSync(currentAddonFastbootPath)) {
143155
fastbootTree = this.treeGenerator(currentAddonFastbootPath);
144156
}
145157

@@ -168,7 +180,7 @@ module.exports = {
168180

169181
// check the parent containing the fastboot directory
170182
const projectFastbootPath = path.join(this.project.root, 'fastboot');
171-
if (existsSync(projectFastbootPath)) {
183+
if (this.existsSync(projectFastbootPath)) {
172184
let fastbootTree = this.treeGenerator(projectFastbootPath);
173185
fastbootTrees.push(fastbootTree);
174186
}

0 commit comments

Comments
 (0)