-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
chore(gatsby-transformer-sqip): improve sqip performance and debug logging #13349
Conversation
This shouldn't happen always - only when there are changes that trigger cache invalidation (such as updating plugin or editing gatsby-config or gatsby-node) - if it happens always, then that's a bug for sure. |
@axe312ger could you provide any insight/response to @pieh's comment above? That will help us understand exactly what you're trying to do here! Thanks! |
I'll try to find a way to reproduce without my project. Maybe within a code-sandbox. Will come back here later. |
Looks like the cache now resets with the expected behaviour. Upgrading all my projects dependencies + recreating the Still: Looks like gatsby resets the caches in a smart way tracking changes of SQIPs take a long time to generate and storing the results inside of SQIP already has two layers of caching, the pure SVG result files are stored to the disk and the data which is accessible thourgh GraphQL is stored via gatsby To workaround the gatsby cache reset, I moved the SQIP cache dir to Did the Gatsby team ever consider a long-term cache or something similar for processor intensive task results? Could be very useful for video conversion plugins as well. Thanks a bunch, |
Improved the loggings and did some tests to check if the fixed queueing and new cache dir is speeding up things. It clearly does: Improved queueing: 289.46 sec -> 160.52 sec
|
Exciting!
It's a somewhat complex problem as it's a high-powered ability to give to a plugin — to be able to permanently cache items. As if they're wrong, it's increasingly harder for a user to fix things. A brief sketch of a design I was thinking through last night. We could create a "permanent" cache in the home directory of the user and cap it's size at say 5% of the total size of the hard drive or 25% of the remaining free space, whichever is larger (numbers are handwavey — Google Chrome does something similar for their cache so we could look into that). We'd count accesses (reads or writes) to the cache and when the cache gets too large evict on a LRU basis. Plugins wanting to store stuff there would add a new If this works, this is also something we'd like to establish as a service for Gatsby Cloud so collaborators on a project would never need to redo transforms. The main difficulty is that cache keys or file names (same thing) need to be globally unique and deterministic. Perhaps as a failsafe against problems with this (as with @pieh's recent discovery), plugins could add to keys a cache "version" number so that if there's ever a problem discovered with the key generation, they can increment the key number. |
3a3d77b
to
f5dfde4
Compare
I thought the same, maybe gatsby can fingerprint these permanent files to reinit the transformation as soon the source file changed. This seems be good input about hashing the files: https://github.com/joliss/fast-js-hash-benchmark For this PR: Just adjusted the readme a little bit more and as Kyle is fine with using I think its ready for a final code review / merge. |
That's exactly how Gatsby works already :-D Whenever Gatsby sees that a file has changed, we create a new
Does this plugin use the contentDigest for creating file names? If so, then it's already ready for permanent caching. This is how gatsby-transformer-sharp works as well. |
@@ -138,7 +134,7 @@ async function sqipContentful({ type, cache, store }) { | |||
const cacheImage = require(`gatsby-source-contentful/cache-image`) | |||
|
|||
const program = store.getState().program | |||
const cacheDir = resolve(`${program.directory}/.cache/sqip/`) | |||
const cacheDir = resolve(`${program.directory}/.cache-sqip/`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps use node_modules/.cache
? #5880
I have the updates ready for to use
|
Hmmm yeah — we changed permissions recently — can you just not force push? We do a squash commit on all PRs so we prefer people don't "clean up" old commits when you're exploring as it's harder to see the history of a PR. |
Weird, got the branch fresh, cherry-picked my two commits on it, still get similar error: $ git push
To github.com:gatsbyjs/gatsby.git
! [rejected] improve-sqip-performance-and-logging -> improve-sqip-performance-and-logging (non-fast-forward)
error: failed to push some refs to 'git@github.com:gatsbyjs/gatsby.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
$ git pull
Already up to date.
$ git push
To github.com:gatsbyjs/gatsby.git
! [rejected] improve-sqip-performance-and-logging -> improve-sqip-performance-and-logging (non-fast-forward)
error: failed to push some refs to 'git@github.com:gatsbyjs/gatsby.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details. |
@axe312ger Hey, could you please try again, we updated our permissions in the meantime. Thanks! |
Ping |
b990e6e
to
3ec3f62
Compare
Sorry. Done :) @KyleAMathews @LekoArts |
3ec3f62
to
8164840
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! seem to work like a charm. Testing it on the gatsby sqip example.
Published in |
Thank you so much! Be aware, I come back soon to push a PR which upgrades SQIP to v1 which is finally async 😏 And adds a huge load of new features: |
Refactor the SQIP generation queuing avoid the primitive previews are generated multiple times for the same image.
Additionally improves debug logging.
Open question:
Seems like gatsby now removes
.cache/sqip
and.cache/caches
when doinggatsby build
. This breaks both caches integrated in the sqip transformer. Usingcache.set/.get
is now completely useless. Was this done on purpose? 😭