From 2a6462641b0197291c08e2fc8e40dacbf43bf893 Mon Sep 17 00:00:00 2001 From: Pascal Hartig Date: Tue, 17 Sep 2019 12:19:41 -0700 Subject: [PATCH] Limit concurrency during plugin compilation Summary: My MBP just crashed again during startup. I would like to understand why every plugin compilation appears to start up a new electron process, but until that's understood and hopefully fixed, it's probably best to limit the number of processes we spawn by setting an upper bound here. N.B. My Linux box doesn't mind this at all. Reviewed By: jknoxville, danielbuechele Differential Revision: D17419289 fbshipit-source-id: a11562a21a984059dc35e826eb20d869df218546 --- package.json | 1 + static/compilePlugins.js | 7 ++++--- yarn.lock | 25 +++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 6de7e8774..165d6df98 100644 --- a/package.json +++ b/package.json @@ -126,6 +126,7 @@ "mkdirp": "^0.5.1", "node-fetch": "^2.3.0", "openssl-wrapper": "^0.3.4", + "p-map": "^3.0.0", "pkg": "^4.3.7", "promise-retry": "^1.1.1", "promisify-child-process": "^3.1.1", diff --git a/static/compilePlugins.js b/static/compilePlugins.js index 8696a1532..77e30f225 100644 --- a/static/compilePlugins.js +++ b/static/compilePlugins.js @@ -12,6 +12,7 @@ const Metro = require('metro'); const util = require('util'); const recursiveReaddir = require('recursive-readdir'); const expandTilde = require('expand-tilde'); +const pMap = require('p-map'); const HOME_DIR = require('os').homedir(); /* eslint-disable prettier/prettier */ @@ -38,12 +39,12 @@ module.exports = async ( fs.mkdirSync(pluginCache); } watchChanges(plugins, reloadCallback, pluginCache, options); - const compilations = Object.values(plugins).map(plugin => { + const compilations = pMap(Object.values(plugins), plugin => { const dynamicOptions = Object.assign(options, {force: false}); return compilePlugin(plugin, pluginCache, dynamicOptions); - }); + }, {concurrency: 4}); - const dynamicPlugins = (await Promise.all(compilations)).filter(c => c != null); + const dynamicPlugins = (await compilations).filter(c => c != null); console.log('✅ Compiled all plugins.'); return dynamicPlugins; }; diff --git a/yarn.lock b/yarn.lock index 3341b2f25..333a10c7f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1484,6 +1484,14 @@ agentkeepalive@^2.2.0: resolved "https://registry.yarnpkg.com/agentkeepalive/-/agentkeepalive-2.2.0.tgz#c5d1bd4b129008f1163f236f86e5faea2026e2ef" integrity sha1-xdG9SxKQCPEWPyNvhuX66iAm4u8= +aggregate-error@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/aggregate-error/-/aggregate-error-3.0.0.tgz#5b5a3c95e9095f311c9ab16c19fb4f3527cd3f79" + integrity sha512-yKD9kEoJIR+2IFqhMwayIBgheLYbB3PS2OBhWae1L/ODTd/JF/30cW0bc9TqzRL3k4U41Dieu3BF4I29p8xesA== + dependencies: + clean-stack "^2.0.0" + indent-string "^3.2.0" + ajv-keywords@^3.4.0: version "3.4.1" resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-3.4.1.tgz#ef916e271c64ac12171fd8384eaae6b2345854da" @@ -2468,6 +2476,11 @@ class-utils@^0.3.5: isobject "^3.0.0" static-extend "^0.1.1" +clean-stack@^2.0.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-2.2.0.tgz#ee8472dbb129e727b31e8a10a427dee9dfe4008b" + integrity sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A== + cli-boxes@^2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/cli-boxes/-/cli-boxes-2.2.0.tgz#538ecae8f9c6ca508e3c3c95b453fe93cb4c168d" @@ -4765,6 +4778,11 @@ indent-string@^2.1.0: dependencies: repeating "^2.0.0" +indent-string@^3.2.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/indent-string/-/indent-string-3.2.0.tgz#4a5fd6d27cc332f37e5419a504dbb837105c9289" + integrity sha1-Sl/W0nzDMvN+VBmlBNu4NxBckok= + indexof@0.0.1: version "0.0.1" resolved "https://registry.yarnpkg.com/indexof/-/indexof-0.0.1.tgz#82dc336d232b9062179d05ab3293a66059fd435d" @@ -6863,6 +6881,13 @@ p-locate@^3.0.0: dependencies: p-limit "^2.0.0" +p-map@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/p-map/-/p-map-3.0.0.tgz#d704d9af8a2ba684e2600d9a215983d4141a979d" + integrity sha512-d3qXVTF/s+W+CdJ5A29wywV2n8CQQYahlgz2bFiA+4eVNJbHJodPZ+/gXwPGh0bOqA+j8S+6+ckmvLGPk1QpxQ== + dependencies: + aggregate-error "^3.0.0" + p-reduce@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/p-reduce/-/p-reduce-1.0.0.tgz#18c2b0dd936a4690a529f8231f58a0fdb6a47dfa"