From 2d23f99b00bb833b432a09958163458dca6b162d Mon Sep 17 00:00:00 2001 From: Sanjaiyan Parthipan Date: Fri, 20 Oct 2023 12:49:06 +0530 Subject: [PATCH 1/5] perf: async concurent --- libraries/rush-lib/scripts/copyEmptyModules.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/rush-lib/scripts/copyEmptyModules.js b/libraries/rush-lib/scripts/copyEmptyModules.js index 2f5e2f380cc..8ea7b8965ea 100644 --- a/libraries/rush-lib/scripts/copyEmptyModules.js +++ b/libraries/rush-lib/scripts/copyEmptyModules.js @@ -50,12 +50,12 @@ module.exports = { const folderItems = await FileSystem.readFolderItemsAsync( relativeFolderPath ? `${jsInFolderPath}/${relativeFolderPath}` : jsInFolderPath ); - for (const folderItem of folderItems) { + await Promise.all(folderItems.map(async (folderItem) => { const itemName = folderItem.name; const relativeItemPath = relativeFolderPath ? `${relativeFolderPath}/${itemName}` : itemName; if (folderItem.isDirectory()) { - await searchAsync(relativeItemPath); + return searchAsync(relativeItemPath); } else if (folderItem.isFile() && itemName.endsWith(JS_FILE_EXTENSION)) { const jsInPath = `${jsInFolderPath}/${relativeItemPath}`; const jsFileText = await FileSystem.readFileAsync(jsInPath); @@ -73,10 +73,10 @@ module.exports = { terminal.writeVerboseLine(`Copying ${inDtsPath} to ${outDtsPath}`); // We know this is a file, don't need the redundant checks in FileSystem.copyFileAsync const buffer = await FileSystem.readFileToBufferAsync(inDtsPath); - await FileSystem.writeFileAsync(outDtsPath, buffer, { ensureFolderExists: true }); + return FileSystem.writeFileAsync(outDtsPath, buffer, { ensureFolderExists: true }); } } - } + })); } await searchAsync(undefined); From 942424a1a48abc802f33471906a0e0db434b1216 Mon Sep 17 00:00:00 2001 From: Sanjaiyan Parthipan Date: Fri, 20 Oct 2023 07:33:48 +0000 Subject: [PATCH 2/5] fix: changelog --- .../sanjaiyan-async-concurrent_2023-10-20-07-32.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 common/changes/@microsoft/rush/sanjaiyan-async-concurrent_2023-10-20-07-32.json diff --git a/common/changes/@microsoft/rush/sanjaiyan-async-concurrent_2023-10-20-07-32.json b/common/changes/@microsoft/rush/sanjaiyan-async-concurrent_2023-10-20-07-32.json new file mode 100644 index 00000000000..1026de56680 --- /dev/null +++ b/common/changes/@microsoft/rush/sanjaiyan-async-concurrent_2023-10-20-07-32.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@microsoft/rush", + "comment": "performance improvements by running asynchronous code concurrently using Promise.all", + "type": "none" + } + ], + "packageName": "@microsoft/rush" +} \ No newline at end of file From 1ff78345f2f9377d5eb4465e6f9309204ec5192f Mon Sep 17 00:00:00 2001 From: Sanjaiyan Parthipan Date: Fri, 27 Oct 2023 07:11:27 +0000 Subject: [PATCH 3/5] perf: adding with limited concurrency --- libraries/rush-lib/scripts/copyEmptyModules.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/rush-lib/scripts/copyEmptyModules.js b/libraries/rush-lib/scripts/copyEmptyModules.js index 8ea7b8965ea..ec745bd3a54 100644 --- a/libraries/rush-lib/scripts/copyEmptyModules.js +++ b/libraries/rush-lib/scripts/copyEmptyModules.js @@ -1,6 +1,6 @@ 'use strict'; -const { FileSystem } = require('@rushstack/node-core-library'); +const { FileSystem, Async } = require('@rushstack/node-core-library'); const JS_FILE_EXTENSION = '.js'; const DTS_FILE_EXTENSION = '.d.ts'; @@ -50,7 +50,7 @@ module.exports = { const folderItems = await FileSystem.readFolderItemsAsync( relativeFolderPath ? `${jsInFolderPath}/${relativeFolderPath}` : jsInFolderPath ); - await Promise.all(folderItems.map(async (folderItem) => { + await Async.forEachAsync(folderItems, async (folderItem) => { const itemName = folderItem.name; const relativeItemPath = relativeFolderPath ? `${relativeFolderPath}/${itemName}` : itemName; @@ -76,7 +76,7 @@ module.exports = { return FileSystem.writeFileAsync(outDtsPath, buffer, { ensureFolderExists: true }); } } - })); + }); } await searchAsync(undefined); From 4138d53026747a46b9afbc489616459fd0aa26db Mon Sep 17 00:00:00 2001 From: Sanjaiyan Parthipan Date: Fri, 27 Oct 2023 13:34:41 +0530 Subject: [PATCH 4/5] Update libraries/rush-lib/scripts/copyEmptyModules.js Co-authored-by: Daniel <3473356+D4N14L@users.noreply.github.com> --- libraries/rush-lib/scripts/copyEmptyModules.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/rush-lib/scripts/copyEmptyModules.js b/libraries/rush-lib/scripts/copyEmptyModules.js index ec745bd3a54..fcb4eedd61e 100644 --- a/libraries/rush-lib/scripts/copyEmptyModules.js +++ b/libraries/rush-lib/scripts/copyEmptyModules.js @@ -73,7 +73,7 @@ module.exports = { terminal.writeVerboseLine(`Copying ${inDtsPath} to ${outDtsPath}`); // We know this is a file, don't need the redundant checks in FileSystem.copyFileAsync const buffer = await FileSystem.readFileToBufferAsync(inDtsPath); - return FileSystem.writeFileAsync(outDtsPath, buffer, { ensureFolderExists: true }); + await FileSystem.writeFileAsync(outDtsPath, buffer, { ensureFolderExists: true }); } } }); From aef5a502eee6a4c557bfa9de6ad515ad21ebf8fd Mon Sep 17 00:00:00 2001 From: Sanjaiyan Parthipan Date: Fri, 27 Oct 2023 13:34:49 +0530 Subject: [PATCH 5/5] Update libraries/rush-lib/scripts/copyEmptyModules.js Co-authored-by: Daniel <3473356+D4N14L@users.noreply.github.com> --- libraries/rush-lib/scripts/copyEmptyModules.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/rush-lib/scripts/copyEmptyModules.js b/libraries/rush-lib/scripts/copyEmptyModules.js index fcb4eedd61e..9c9b5bc718e 100644 --- a/libraries/rush-lib/scripts/copyEmptyModules.js +++ b/libraries/rush-lib/scripts/copyEmptyModules.js @@ -55,7 +55,7 @@ module.exports = { const relativeItemPath = relativeFolderPath ? `${relativeFolderPath}/${itemName}` : itemName; if (folderItem.isDirectory()) { - return searchAsync(relativeItemPath); + await searchAsync(relativeItemPath); } else if (folderItem.isFile() && itemName.endsWith(JS_FILE_EXTENSION)) { const jsInPath = `${jsInFolderPath}/${relativeItemPath}`; const jsFileText = await FileSystem.readFileAsync(jsInPath);