Use Promise.all on batches of 32
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
4c66e9f8a5
commit
0360382882
|
@ -46,8 +46,12 @@ export async function optimizeImages() {
|
||||||
const numberOfWorkers = Math.min(cpus().length, 8);
|
const numberOfWorkers = Math.min(cpus().length, 8);
|
||||||
const imagePool = new ImagePool(numberOfWorkers);
|
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(
|
await Promise.all(
|
||||||
imagePaths.map(async (imagePath) => {
|
imagePaths.slice(i, i + batchSize).map(async (imagePath) => {
|
||||||
const imageStartTime = Date.now();
|
const imageStartTime = Date.now();
|
||||||
|
|
||||||
const sourcePath = path.join(SOURCE_DIRECTORY, imagePath);
|
const sourcePath = path.join(SOURCE_DIRECTORY, imagePath);
|
||||||
|
@ -104,6 +108,7 @@ export async function optimizeImages() {
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
await imagePool.close();
|
await imagePool.close();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue