Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

img-dim is slow and not cached #107

Open
theor opened this issue Sep 28, 2021 · 7 comments
Open

img-dim is slow and not cached #107

theor opened this issue Sep 28, 2021 · 7 comments

Comments

@theor
Copy link

theor commented Sep 28, 2021

Hello,

I realized that the img processing is executed multiple times per image - typically, if I add an image to a blog post, it will get processed 3 times (the blog post page itself, the /posts list page, the / list page) + once per tag . I have a site icon processed 22 times per build, for a total of 1721ms according to the 11ty benchmark log.

Caching would be great ; I see a solution in 2 steps :

  • keep an in-memory, transient cache indexed by path: should be easy to do. fill the cache in img-dim, invalidate it when the image changes. pay the cost once per image when starting watch mode, still way better
  • then get to a persistent cache. we could write an image-hashes.json file with the previous hash and generated file path, check it once during watch startup and compare the stored hashes against the actual hashes to invalidate or not the cache entries.

Thoughts ?

Also: it looks like gif2mp4 (which is even slower) is not running if an mp4 file already exists in the source folder (see

if (await exists(dest)) {
). is that intended to act as a basic cache ? in that case it should be if (await exists(join("_site", dest))) { instead of if (await exists(dest)) {

@cramforce
Copy link
Collaborator

Did you see which part of img-dim is slow?

I'm definitely supportive of caching it. I just have never seen it being slow. You definitely found a bug for the GIF special case, but otherwise the image processing is the slow part and obviously that is being done only once per build.

@theor
Copy link
Author

theor commented Sep 28, 2021

await sizeOf("_site/" + src); is slow and done every time (that's where the time is spent the next 21 times in my example)
srcset doing all the actual resizing is slow too, but done only once

@cramforce
Copy link
Collaborator

OK. sizeOf is an O(1) operation but I can see it getting a factor for N images :)

I'm definitely supportive of caching it.

@cozarkd
Copy link

cozarkd commented Dec 29, 2021

I'm having serious problems with the image processing scripts.
My project had an average of 1-2min building time, now it's +20min. So I can't use that in netlify or cloudflare pages. Probably need to do it locally in a separate script and store the files.

@indcoder
Copy link
Contributor

Agree with @cozarkd . It has dramatically increased the build time and it is taking up so much memory that we cannot now use Netlify for building [so CI/CD is busted].

@cramforce
Copy link
Collaborator

Did you try running .persistimages.sh after a local build? It should eliminate all slowness.

@cozarkd
Copy link

cozarkd commented Dec 30, 2021

Did you try running .persistimages.sh after a local build? It should eliminate all slowness.

oh, I thought that file was for remote images, makes sense now. In my use case I had to implement some features but not the full template. Problem solved, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants