Improve gatsby-develop bootup time (query-on-demand) #7348
-
SummaryWhen developing a Gatsby site there's no need to run all graphql queries before serving the site. Instead Gatsby could run queries for pages as they're requested. This would avoid having to wait for slower queries (like image processing) if you're editing an unrelated part of a site. There's an old PR investigating this at #4775 |
Beta Was this translation helpful? Give feedback.
Replies: 32 comments 1 reply
-
some updates - this is my very WIP and very unclean dev branch - master...pieh:dev-query-on-demand Few notes:
|
Beta Was this translation helpful? Give feedback.
-
Old issues will be closed after 30 days of inactivity. This issue has been quiet for 20 days and is being marked as stale. Reply here or add the label "not stale" to keep this issue open! |
Beta Was this translation helpful? Give feedback.
-
Which is the current status of this PR? It seems to be abandoned, but it looks very promising as it solves one of the main problems when developing with Gatsby. |
Beta Was this translation helpful? Give feedback.
-
@asilgag this has been split out into smaller parts. The first part is to just run image processing on demand, as this is often takes a significant amount of time. There's a PR that's nearly ready to land over at #10964 |
Beta Was this translation helpful? Give feedback.
-
Hey! What's the current status of this feature? Unless I am missing something, I believe this is still a pain as the site grows, correct? Having to process hundreds of images takes 2½ minutes even on a really fast hardware. |
Beta Was this translation helpful? Give feedback.
-
Mine "Generating image thumbnails" takes around 20mins in CircleCI (4454/4454 - 1130.272 s) Can we opt to skip this process? Is thumbnails here = all images? It should regenerate only the modified ones. |
Beta Was this translation helpful? Give feedback.
-
Any update? |
Beta Was this translation helpful? Give feedback.
-
good that i find this issue, i was planning to creating an new issue "disable image generation and give us "fake thumbnails (just the original image) or generic placeholder thumbnails" because sometimes i don't care about the images while running in sad that the option |
Beta Was this translation helpful? Give feedback.
-
I'll add that |
Beta Was this translation helpful? Give feedback.
-
+1, I was also expecting a flag to at least disable the generation of the various thumbs for dev. |
Beta Was this translation helpful? Give feedback.
-
y'all see their experimental incremental build flag? While not a direct solution to the root cause of image generation, it sure does ease the symptoms, especially when paired with a build/CI stack that caches |
Beta Was this translation helpful? Give feedback.
-
Btw if anyone working with |
Beta Was this translation helpful? Give feedback.
-
@jlkiri |
Beta Was this translation helpful? Give feedback.
-
@alexfornuto One example of that: Every time you change the schema or data in a source used with It would be great if usual suspects like image generation was flag on the cache, so you could do it in a granular way if you want to. |
Beta Was this translation helpful? Give feedback.
-
also if you change some component / plugin code and need to see the changes you need to clear the pages cache to get pages rerendered with the new code. |
Beta Was this translation helpful? Give feedback.
-
it is mostly in the development phase where you not care about image quality, but you check complete other functionality |
Beta Was this translation helpful? Give feedback.
-
a granular cache management would be also ok, like:
|
Beta Was this translation helpful? Give feedback.
-
Totally agree with @muescha. I work on a site that has a few thousand pages with lots of images, so when it comes to debugging or making changes to configuration to implement new functionality, the cache gets flushed and it takes a really long time for images to get resized and for pages to be built. It's frustrating enough that we've gone and implemented a yarn command that uses environment variables in order to not build the biggest part of the site, so that local development cycles could be 70% faster. This sort of hack required the least code changes. Ideally, it would be nice to have page queries on demand when in development. Although, I appreciate that this would introduce quite a level of divergence from production cycles, so some issues wouldn't get caught. However, I wonder if run page queries on demand could be run on a separate command that could be evolved over time to address any kind of discrepancies between the two. |
Beta Was this translation helpful? Give feedback.
-
@josephmarkus I'd be interested in seeing your yarn command workaround hack. |
Beta Was this translation helpful? Give feedback.
-
@alexfornuto here it is: In my // at the top of the file
const getGatsbySourceFileSystemPathsToExclude = () => {
// By default we want to make sure that we don't exclude anything
if (process.env.WITHOUT_HUB !== 'true') {
return [];
}
return [`**/content/hub/**`];
}; // inside your plugin array
{
resolve: 'gatsby-source-filesystem',
options: {
path: `${__dirname}/content`,
name: 'content',
ignore: getGatsbySourceFileSystemPathsToExclude(),
},
}, // because those before mentioned Markdown files are handled
// by a custom Gatsby plugin, there's more config for another plugin
{
resolve: 'gatsby-plugin-hub',
options: {
skip: process.env.WITHOUT_HUB,
},
}, And then inside my exports.createPages = async ({ graphql, actions }, pluginOptions) => {
// 'skip' is the option that's defined in `gatsby-config.js` alongside the plugin
if (pluginOptions.skip === 'true') {
// eslint-disable-next-line no-console
console.log(
`This build will not contain Hub pages. Check WITHOUT_HUB flag usage.`,
);
return false;
}
const { createPage } = actions;
return buildHubPages(createPage, graphql);
}; Finally, in my "start:without-hub": "cross-env NODE_ENV=development WITHOUT_HUB=true gatsby develop", The above In my case, the specified folder contains a few thousand Markdown files that I do not want to be processed when I'm looking to get the rest of the application up and running. With this, my build times in development are down from 10 min to 3 min when without cache. Ask away if any of this is unclear 😅 |
Beta Was this translation helpful? Give feedback.
-
instead of the for example see |
Beta Was this translation helpful? Give feedback.
-
I think I'm just out of my depth as a Gatsby user who isn't a JS dev. But thanks for sharing anyway! Hopefully it will help / inspire others. |
Beta Was this translation helpful? Give feedback.
-
Thanks @muescha, that's an interesting approach! @alexfornuto what's the setup like in your project? In my case, I can ignore a particular folder where most content lives. Do you have a similar problem? |
Beta Was this translation helpful? Give feedback.
-
My project is the Pantheon Docs - the big killer is the image building on uncached builds (see #12857), which I think count as queries? Assuming they do, then the folder I'd want for on-demand queries would be |
Beta Was this translation helpful? Give feedback.
-
@alexfornuto I had a look at your project. You have some options here:
There's no one ideal option. Each of one these is a sort of compromise. You might have to pick the least worst option for your setup. Btw, re:
This is how I think it works:
Both of these are separate processes, but parsing and resizing of images would be most expensive in terms of time and resource |
Beta Was this translation helpful? Give feedback.
-
The most annoying process is that when you change something in gatsby-ssr or gatsby-node, sometimes the Gatsby deletes the cache and needs to regenerate the images again!? WHY? |
Beta Was this translation helpful? Give feedback.
-
Hey everyone! We've shipped an initial version of query on demand in 2.27.0 — upgrade & try it out!
Read more about it + some other initiatives we're working on to speedup starting the dev server https://github.com/gatsbyjs/gatsby/blob/master/docs/reference/release-notes/v2.27/index.md |
Beta Was this translation helpful? Give feedback.
-
This got shipped in 2.29 |
Beta Was this translation helpful? Give feedback.
This got shipped in 2.29
https://www.gatsbyjs.com/docs/reference/release-notes/v2.29