Use Promise.all on batches of 32
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Amy 2022-06-04 19:06:45 -04:00
parent 4c66e9f8a5
commit 0360382882
1 changed files with 52 additions and 47 deletions

View File

@ -46,8 +46,12 @@ export async function optimizeImages() {
const numberOfWorkers = Math.min(cpus().length, 8);
const imagePool = new ImagePool(numberOfWorkers);
// process smaller batches in order to reduce memory usage
const batchSize = 32;
for (let i = 0; i < imagePaths.length; i += batchSize) {
await Promise.all(
imagePaths.map(async (imagePath) => {
imagePaths.slice(i, i + batchSize).map(async (imagePath) => {
const imageStartTime = Date.now();
const sourcePath = path.join(SOURCE_DIRECTORY, imagePath);
@ -104,6 +108,7 @@ export async function optimizeImages() {
);
})
);
}
await imagePool.close();