Right now my Hugo site takes about 30 seconds to rebuild when I add/edit a post. I’m probably an extreme case as I’ve got over 5K blog entries. I can live with this but I was wondering if there is some way to minimize that time to make editing a bit quicker. So for example, my blog theme includes a count for categories and tags, and if I removed that, would Hugo then not bother updating existing entries? (I’ve got pagination disabled already.)
There is currently no partial rebuilds, so if you have turned off pagination, renders to memory (in server mode) – then your best bet is to make the templates do less. 30 seconds sounds on the long side for 5K posts, so I would watch out for page the loops, esp. in the single post template.
Some of this is optimized by Hugo (read cached), but if you for every page iterate over all the pages in the site to calculate something, that loop has a cost. It is pretty fast by itself, but times 5000 … And if you have many of these, maybe with some nested inner loops …
This makes sense, but would you be able to share a real example of this? Again - I know loops of course, but I’m just wondering if you can provide a practical example of what you mean. I certainly do not expect you to look at my code, but if you’re really bored (grin), I do have my site up on GitHub - https://github.com/cfjedimaster/raymondcamdendotcom. Again, I’m definitely not asking you to ‘fix’ my site. People ask me that all the time and it’s frustrating, but any real examples would be appreciated, and even if not, thank you for the help so far.
If you really like that theme I would use something like this for “writing articles”:
hugo server -t <some-other-theme>
Also, if you control the theme, and we had a “dev flag” (I use the buildDraft flag for this), you could put a conditional around the expensive parts: Don’t render when in dev mode.
But the constructs in the theme you use isn’t unusual, so someone should do something about it. I think there is a GitHub issue about it.
Oh, the dev flag sounds like a great idea actually. And hell, I’ve already got my own mods to the theme already so I wouldn’t be cluttering up the ‘real’ theme if that makes sense. I’ll give that a shot.
And I just did. By using a conditional in sidebar and profile, I’m now down to about 4.5 seconds locally. Awesome! Thanks for the tips!
Btw, is there already an ER for something like, “render this partial once and never rerun it - use the output from last time”? That would have solved my problem too, and seems like it would be helpful for a lot of folks.