Is this performance typical of hugo sites? I have a 753 page blog with pagination. Should it be taking 11 seconds to generate? The newest release says about 1 ms per page.

Started building sites …
Built site for language en:
0 of 1 draft rendered
0 future content
0 expired content
753 pages created
0 non-page files copied
76 paginator pages created
0 tags created
24 categories created
total in 11518 ms

No, that is not typical. What version are you using? What O/S? Your files on loppy drives, hard drives, network shares?

It says “about 1ms per page”, but we don’t control the user’s templates and data. There are plenty of ways to create slow and ineffective Hugo sites. But there are also ways to fix them.

But that means you have have to show us your source code. Do you have a GitHub link or similar?

I am curious if there are obvious examples of what not to do in templating that would make things slow and whether it’s worth adding to the docs.

There have been some obvious examples in the past here on the forum, I may try to search for them.

We have been doing some work to help this with some caching, but there still are improvements to be had in this area.

So, as in software engineering in general, be aware of that inner loop.

So listing 10 pages with a where clause on the home page is fine. Doing the same for every page gets expensive (which means we should cache it), but still surprisingly fast with Go. Adding more loops inside those loops … It gets exponential.

First step is to use step analysis to see which steps in the build process are taking so long:

hugo --stepAnalysis

Using pygments for syntax highlighting (or other 3rd party renderers) often slows things way down.

Awesome. Thanks. Here’s the output:

Started building sites …
Go initialization:
9.89709075s (9.898400111s) 16.33 MB 127498 Allocs
initialize & template prep:
21.482323ms (9.92054038s) 0.76 MB 9779 Allocs
load data:
744.291µs (9.921336199s) 0.00 MB 34 Allocs
load i18n:
588.736µs (9.921958376s) 0.00 MB 58 Allocs
read pages from source:
170.044292ms (10.092088664s) 29.28 MB 228951 Allocs
convert source:
59.686473ms (10.151877194s) 40.44 MB 261760 Allocs
build taxonomies:
10.876287ms (10.162877394s) 1.27 MB 52218 Allocs
render and write aliases:
44.265859ms (10.207347914s) 16.65 MB 13207 Allocs
render and write taxonomies:
81.467165ms (10.289054238s) 25.34 MB 294452 Allocs
render & write taxonomy lists:
36.807µs (10.289194198s) 0.00 MB 39 Allocs
render and write lists:
4.005292ms (10.293365139s) 0.58 MB 5062 Allocs
render and write pages:
11.194472466s (21.488032358s) 3297.99 MB 74994604 Allocs
render and write homepage:
508.799183ms (21.997041309s) 130.71 MB 1192404 Allocs
render and write Sitemap:
72.12147ms (22.069648172s) 7.01 MB 153454 Allocs
render and write robots.txt:
20.273µs (22.069940241s) 0.00 MB 13 Allocs

Looks like I have some templating issue. I searched through it and I have this embedded in the footer of each page

   var posts = [];
   {{ range .Site.Pages }}
      posts.push(["{{ .RelPermalink }}", "{{.Title}}"]);
   {{ end }}
   rand = Math.floor(Math.random() * posts.length)
   link = document.getElementById("randomizer")
   link.innerHTML = posts[rand][1]
   link.href = posts[rand][0]

It’s a function to generate a random page as a link in the blog so people can continue browsing. Is there a more efficient way to do this in Hugo?

Thanks for the help!

Currently not.

This would be perfect for you:

But someone need to do some work and it is not on my list of stuff I’m planning to work on.