Make yarn start twice as fast

Summary:
Compilation is a mixture of I/O and CPU work, so there's some good optimisation potential even on a single thread by running the promises concurrently. The downside is that the output is a bit garbled, but it's quite a bit faster for me.

To test this, I applied this diff so I could just `time yarn start` for an entire run.

```
 diff --git a/xplat/sonar/src/init.js b/xplat/sonar/src/init.js
 --- a/xplat/sonar/src/init.js
+++ b/xplat/sonar/src/init.js
@@ -80,4 +80,5 @@
   dispatcher(store, logger);
   // make init function callable from outside
   window.Flipper.init = init;
+  window.close();
 });
```

## Before

**Cold Start**
```
696.89user 93.21system 4:21.44elapsed 302%CPU (0avgtext+0avgdata 1111448maxresident)k
1416inputs+372824outputs (3major+28155897minor)pagefaults 0swaps
```

**Hot Start**
```
6.87user 1.62system 0:17.32elapsed 49%CPU (0avgtext+0avgdata 249264maxresident)k
216inputs+182912outputs (0major+251426minor)pagefaults 0swaps
```

## After

**Cold Start**

```
736.86user 95.47system 1:53.13elapsed 735%CPU (0avgtext+0avgdata 970616maxresident)k
42864inputs+356776outputs (42major+25299531minor)pagefaults 0swaps
```

**Hot Start**

```
6.85user 1.60system 0:15.93elapsed 53%CPU (0avgtext+0avgdata 269420maxresident)k
2592inputs+197904outputs (0major+260099minor)pagefaults 0swaps
```

## Summary

It's beneficial in both cases, but the wall clock time for cold start goes from *4:21.44* to *1:53.13* for me (mind that this is a single sample). This is a 2.3x speed-up!

Reviewed By: jknoxville

Differential Revision: D16359215

fbshipit-source-id: 62257ec3bdefbf98356f5ac9418c4906f7cb4b1b
This commit is contained in:
Pascal Hartig
2019-07-18 10:35:20 -07:00
committed by Facebook Github Bot
parent 453b04a008
commit 10559a188f

View File

@@ -38,18 +38,12 @@ module.exports = async (
fs.mkdirSync(pluginCache);
}
watchChanges(plugins, reloadCallback, pluginCache, options);
const dynamicPlugins = [];
for (const plugin of Object.values(plugins)) {
const compilations = Object.values(plugins).map(plugin => {
const dynamicOptions = Object.assign(options, {force: false});
const compiledPlugin = await compilePlugin(
plugin,
pluginCache,
dynamicOptions,
);
if (compiledPlugin) {
dynamicPlugins.push(compiledPlugin);
}
}
return compilePlugin(plugin, pluginCache, dynamicOptions);
});
const dynamicPlugins = (await Promise.all(compilations)).filter(c => c != null);
console.log('✅ Compiled all plugins.');
return dynamicPlugins;
};
@@ -129,7 +123,7 @@ function entryPointForPluginFolder(pluginPath) {
return fs
.readdirSync(pluginPath)
.filter(name =>
/*name.startsWith('flipper-plugin') && */ fs
fs
.lstatSync(path.join(pluginPath, name))
.isDirectory(),
)