How to make Hugo faster?

Hello,

I love Hugo but I have an issue with Hugo’s speed: my 214 short pages take around 5 seconds* to built (the typical .md file size is 2kb). I think that’s an issue since I’m not achieving the speed that other people report.

Who can help me decipher the step analysis below? Also, is there perhaps information about troubleshooting slow Hugo instances?

*: Time seems slightly more but haven’t yet actually timed it.

I’m using Hugo 0.14 on Windows 7 SP1.

PS I:\site> hugo server --buildDrafts --baseUrl=http://localhost/  --watch --stepAnalysis
initialize & template prep:
        78.0045ms (80.0046ms)       1.38 MB     16723 Allocs
load data:
        1ms (82.0047ms)             0.01 MB     120 Allocs
import pages:
        122.007ms (205.0118ms)     27.79 MB     300521 Allocs
build taxonomies:
        2.0001ms (207.0119ms)       0.16 MB     4693 Allocs
render and write aliases:
        3.0002ms (210.0121ms)       0.02 MB     294 Allocs
render and write taxonomies:
        11.0006ms (222.0127ms)      0.38 MB     9115 Allocs
render & write taxonomy lists:
        0 (224.0129ms)              0.02 MB     401 Allocs
render and write lists:
        128.0073ms (352.0202ms)     12.54 MB     257273 Allocs
render and write pages:
        4.2122409s (4.5642611s)     1047.21 MB     25221143 Allocs
render and write homepage:
        55.0031ms (4.6202643s)      4.64 MB     118421 Allocs
render and write Sitemap:
        19.0011ms (4.6402655s)      1.63 MB     38839 Allocs
208 of 208 drafts rendered
0 future content
214 pages created
0 paginator pages created
24 categories created
3 tags created
in 4597 ms
Watching for changes in I:\site/{data,content,layouts,static,themes\lanyon}
Serving pages from I:\site\public
Web Server is available at http://127.0.0.1:1313/
Press Ctrl+C to stop

Change detected, rebuilding site
2015-08-20 16:21 +0200
initialize & template prep:
        35.0650056s (39.7082712s)     1.86 MB     19588 Allocs
load data:
        0 (39.7092713s)               0.01 MB     120 Allocs
import pages:
        138.0079ms (39.8472792s)      27.77 MB     300153 Allocs
build taxonomies:
        1.0001ms (39.8502794s)        0.16 MB     4694 Allocs
render and write aliases:
        2.0001ms (39.8522795s)        0.01 MB     226 Allocs
render and write taxonomies:
        12.0007ms (39.8652802s)       0.38 MB     9116 Allocs
render & write taxonomy lists:
        0 (39.8662803s)               0.02 MB     401 Allocs
render and write lists:
        126.0072ms (39.9932875s)      12.27 MB     257191 Allocs
render and write pages:
        4.3172469s (44.3125346s)      1051.90 MB     25221238 Allocs
render and write homepage:
        57.0032ms (44.3695378s)       5.31 MB     118423 Allocs
render and write Sitemap:
        17.001ms (44.3885389s)        1.63 MB     38824 Allocs
208 of 208 drafts rendered
0 future content
214 pages created
0 paginator pages created
24 categories created
3 tags created
in 4730 ms

Do you have either (or both):

  1. “lots of” media files in /content?
  2. “lots of” data files in /data?

There are two GitHub issue open about this – the first one about to be fixed.

Hugo startup (with --watch) was slow for me when on Windows a few weeks ago, but it’s much faster now. I’m tracking the development version from Github. I’ve never seen it slow like that on Linux. Can you try the latest dev version?

Thanks for the replies.

  1. I have 4 folders in /content/ and 214 .md files. No media or other files.
  2. My /data/ is empty.

Is that the current Github branch? I don’t know how to compile Hugo from that (not a developer here :slight_smile: ).

The answer lies in that 1 GB allocation. But it you just have 200 md files … it’s hard to say without seeing the actual project.

The problem seems to be in my sidebar.html file. With that partial enabled:

208 of 208 drafts rendered
0 future content
214 pages created
0 paginator pages created
29 categories created
3 tags created
in 5660 ms

Without that partial:

208 of 208 drafts rendered
0 future content
214 pages created
0 paginator pages created
29 categories created
3 tags created
in 576 ms

In sidebar.html I use several loops to generate an alphabetically list of all posts in a category. I do that like this:

{{ range $.Site.Pages.ByTitle }}
  {{ if and (in .Params.categories "Category") (in .Params.categories "sub-category") }}
    <li><a href="{{ .Permalink }}">{{ .Title }}</a>
        {{ if .Draft }} * {{ end }}</li>
  {{ end }}
{{ end }}

Is there perhaps an error in that approach or can I change it to make it run more efficient?

OK, I think your main issue here has been solved in the lastest Hugo 0.15-DEV – but it still looks very ineffective.

That’s probably because it is ineffective. :slight_smile: But I could not come up with another way that worked from the things I tried.

If someone knows how to do this efficiently, I’d love to hear that.

You could revisit the sort function, that has been revamped in Hugo 0.15-DEV, it now supports page sorting.

Thanks, then I’ll revisit alphabetical sorting with Hugo 0.15. In the meantime I’ll need to remove all the loops so that I can at least work efficiently with Hugo 0.14. Can you share a good (meaning, efficient) way to get a list of posts from two categories?

I ended up with this inefficient way since I couldn’t get the other ways to work (I tried again tonight, repeatedly).

Not really helpful to you in short term, but I created this:

That seems like a good idea. Can I help with that issue in a practical way? (I can’t code in Go, but perhaps I can do something else)