Today I tried switching to a new theme — the “Bootstrap 4 alpha” theme at https://github.com/alanorth/hugo-theme-bootstrap4-blog
I immediately noticed a couple of problems. First of all, it was taking over 2 minutes to render my site; and secondly, almost all the posts were being missed.
% hugo --stepAnalysis
Started building sites ...
Go initialization:
3.533811622s (3.535578132s) 6.12 MB 71418 Allocs
initialize:
277.577µs (3.53594467s) 0.17 MB 276 Allocs
load data:
3.002568ms (3.539011427s) 0.06 MB 1278 Allocs
load i18n:
573ns (3.539063599s) 0.00 MB 0 Allocs
read pages from source:
913.070545ms (4.452292788s) 119.12 MB 3074045 Allocs
convert source:
335.236608ms (4.787836593s) 105.54 MB 831970 Allocs
build Site meta:
87.606369ms (4.875880306s) 4.63 MB 149951 Allocs
prepare pages:
6.426753969s (11.303129469s) 76.02 MB 798712 Allocs
render and write aliases:
2.051386ms (11.305582615s) 0.02 MB 221 Allocs
render and write pages:
2m40.103532343s (2m51.409721918s) 36652.70 MB 964158256 Allocs
render and write Sitemap:
236.939836ms (2m51.647254629s) 25.27 MB 537135 Allocs
render and write robots.txt:
20.683µs (2m51.647944767s) 0.00 MB 8 Allocs
render and write 404:
165.863µs (2m51.649152121s) 0.01 MB 147 Allocs
Built site for language en:
0 draft content
0 future content
0 expired content
2321 regular pages created
5709 other pages created
0 non-page files copied
8003 paginator pages created
5702 tags created
2 categories created
total in 168114 ms
After some experimentation, I determined that the common factor causing pages to vanish from the output was that they had the line
layout = "post"
in the TOML frontmatter. They had this as a side effect of bulk converting them from WordPress. I don’t know whether this counts as a bug or not?
I wrote a quick sed
incantation to remove that line from every file, and also remove a couple of other unnecessary lines (categories and author). This has reduced the run time somewhat, and the posts now all appear, but it’s still slow, so my secondary issue is performance:
% hugo --stepAnalysis
Started building sites ...
Go initialization:
1.011678455s (1.012267451s) 6.13 MB 71433 Allocs
initialize:
232.278µs (1.012539412s) 0.17 MB 276 Allocs
load data:
1.142027ms (1.013765438s) 0.06 MB 1278 Allocs
load i18n:
331ns (1.01380913s) 0.00 MB 0 Allocs
read pages from source:
491.554132ms (1.505508617s) 103.52 MB 2376479 Allocs
convert source:
197.364436ms (1.703117013s) 105.52 MB 831901 Allocs
build Site meta:
27.543657ms (1.73092476s) 4.27 MB 136336 Allocs
prepare pages:
3.189907433s (4.921231731s) 76.11 MB 798736 Allocs
render and write aliases:
8.042099ms (4.929590933s) 0.02 MB 220 Allocs
render and write pages:
4m29.984140654s (4m34.914395447s) 35765.13 MB 946783013 Allocs
render and write Sitemap:
278.499853ms (4m35.193721854s) 25.06 MB 537141 Allocs
render and write robots.txt:
15.514µs (4m35.194282554s) 0.00 MB 8 Allocs
render and write 404:
490.542µs (4m35.195725495s) 0.01 MB 147 Allocs
Built site for language en:
0 draft content
0 future content
0 expired content
2321 regular pages created
5709 other pages created
0 non-page files copied
7549 paginator pages created
5702 tags created
2 categories created
total in 274184 ms
I’m using release 0.19:
% hugo version
Hugo Static Site Generator v0.19 darwin/amd64 BuildDate: 2017-02-27T12:36:32-06:00
If I switch back to the old theme, everything renders in a reasonable amount of time again:
% hugo --stepAnalysis
Started building sites ...
Go initialization:
134.523734ms (135.103929ms) 5.22 MB 55176 Allocs
initialize:
254.437µs (135.413814ms) 0.17 MB 296 Allocs
load data:
69.402µs (135.517164ms) 0.01 MB 45 Allocs
load i18n:
263ns (135.56444ms) 0.00 MB 0 Allocs
read pages from source:
278.998834ms (414.6632ms) 103.23 MB 2367197 Allocs
convert source:
148.017776ms (562.899758ms) 105.53 MB 831901 Allocs
build Site meta:
27.295549ms (590.478514ms) 4.26 MB 136323 Allocs
prepare pages:
2.261568164s (2.85234764s) 76.17 MB 798740 Allocs
render and write aliases:
470.861µs (2.85305317s) 0.02 MB 220 Allocs
render and write pages:
2.31579503s (5.169258963s) 219.21 MB 4637326 Allocs
render and write Sitemap:
297.951902ms (5.467664325s) 39.23 MB 737082 Allocs
render and write robots.txt:
16.477µs (5.468096967s) 0.00 MB 8 Allocs
render and write 404:
369.684µs (5.46895659s) 0.02 MB 323 Allocs
Built site for language en:
0 draft content
0 future content
0 expired content
2321 regular pages created
5709 other pages created
0 non-page files copied
465 paginator pages created
5702 tags created
2 categories created
total in 5334 ms
So, this is a theme problem, yes? Any idea how I could work out where the performance issues are coming from?