statamic / ssg

The official Statamic Static Site Generator
229 stars 23 forks source link

Optimize performance when gathering content pages #154

Closed o1y closed 2 weeks ago

o1y commented 7 months ago

When you have a lot of content, Statamic allows us to optimize ssg build time by using spatie/fork dependency to have concurrent builds. However, the step "Gathering content files" still takes a long time, because it is not been executed concurrently. In my case this took around 30 seconds for ~5k entries.

Some background, why this takes so long on larger sites: Everytime you fetch the url() from an Entry, it runs the build() function from Statamic\Routing\UrlBuilder, which is augmenting all fields just to build the url. If an entry has a lot of content fields, this could take a while. Some entries took up to 50ms for me to just return the url.

The best approach to speed up the UrlBuilder here would be to only augmenting those fields, which are required for the URL (possibly by parsing the params from the Collection url string first). That requires a bit more effort in the statamic/cms project.

I made it a bit easier by running the generation of all StaticSite\Page objects in parallel via spatie/fork. That speeds up the "Gathering Content Pages" part for me by 83% (from 30s to only 5s). However, that depends on how much cores you have on your machine. 🚀

jasonvarga commented 1 week ago

Did you close this because url() is faster in Statamic 5?