diff --git a/.gitignore b/.gitignore index c6e09955..9bb7ed55 100644 --- a/.gitignore +++ b/.gitignore @@ -28,4 +28,4 @@ yarn-error.log* /public/events.ics # Images should be optimized -/public/images \ No newline at end of file +# /public/images \ No newline at end of file diff --git a/scripts/optimize-images.ts b/scripts/optimize-images.ts index aa543efc..f5d0139f 100644 --- a/scripts/optimize-images.ts +++ b/scripts/optimize-images.ts @@ -36,14 +36,19 @@ void optimizeImages(); export async function optimizeImages() { const imagePaths = await getFilePathsInDirectory(SOURCE_DIRECTORY); - await fse.emptyDir(DESTINATION_DIRECTORY); + // await fse.emptyDir(DESTINATION_DIRECTORY); // maximum number of workers is 4 in order to avoid running out of memory const numberOfWorkers = Math.min(cpus().length, 4); const imagePool = new ImagePool(numberOfWorkers); + let count = 0; await Promise.all( imagePaths.map(async (imagePath) => { + console.time(`on file ${imagePath}`); + count += 1; + const num = count; + console.time(`overall-timer${num}`); const sourcePath = path.join(SOURCE_DIRECTORY, imagePath); const destinationPath = path.join(DESTINATION_DIRECTORY, imagePath); const fileExtension = imagePath.split(".").pop() ?? ""; @@ -54,7 +59,10 @@ export async function optimizeImages() { return; } + console.time(`read-file-timer${num}`); const rawImageFile = await fse.readFile(sourcePath); + console.timeEnd(`read-file-timer${num}`); + const ingestedImage = imagePool.ingestImage(rawImageFile); const { width, height } = getImageDimensions(rawImageFile); @@ -84,6 +92,7 @@ export async function optimizeImages() { const encodedImage = await ingestedImage.encodedWith[encoder]; await fse.outputFile(destinationPath, encodedImage.binary); + console.timeEnd(`overall-timer${num}`); }) );