From 19f231f0eef47fcd18a4c1862807d1c3a1fa14e5 Mon Sep 17 00:00:00 2001 From: Jason Bedard Date: Tue, 22 Oct 2024 13:57:12 -0700 Subject: [PATCH] perf(js_run_devserver): delete files in parallel --- js/private/js_run_devserver.mjs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/js/private/js_run_devserver.mjs b/js/private/js_run_devserver.mjs index 8cdefc31a..52e8c4329 100644 --- a/js/private/js_run_devserver.mjs +++ b/js/private/js_run_devserver.mjs @@ -250,7 +250,7 @@ async function syncRecursive(src, dst, sandbox, writePerm) { async function deleteFiles(previousFiles, updatedFiles, sandbox) { const startTime = perf_hooks.performance.now() - let totalDeleted = 0 + const deletions = [] // Remove files that were previously synced but are no longer in the updated list of files to sync const updatedFilesSet = new Set(updatedFiles) @@ -279,18 +279,22 @@ async function deleteFiles(previousFiles, updatedFiles, sandbox) { mkdirs.clear() const rmPath = path.join(sandbox, f) - try { - fs.rmSync(rmPath, { recursive: true, force: true }) - } catch (e) { - console.error( - `An error has occurred while deleting the synced file ${rmPath}. Error: ${e}` - ) - } - totalDeleted++ + deletions.push( + fs.promises + .rm(rmPath, { recursive: true, force: true }) + .catch((e) => + console.error( + `An error has occurred while deleting the synced file ${rmPath}. Error: ${e}` + ) + ) + ) } + await Promise.all(deletions) + var endTime = perf_hooks.performance.now() + const totalDeleted = deletions.length if (totalDeleted > 0) { console.error( `${totalDeleted} file${totalDeleted > 1 ? 's' : ''}/folder${