My site build by Hugo have about 1600 posts, hugo server very slow

My site build by Hugo have about 1600 posts, hugo server very slow

Need about 8 mins to built

Whether beacuse posts too many?

How make Hugo build more quickly?

Hugo version is 0.62.2


Read the build performance docs; your theme is doing something that doesn’t scale well. Without a copy of the repo, it’s hard to say what, but you probably have a very expensive partial that gets loaded on every page, which can be found with the --templateMetrics option, and likely sped up by using partialCached.

For example, my recipe site has a very lean theme, and builds over 18,000 pages in 18 seconds on a 12-inch MacBook. My blog theme is a lot more complicated, but careful use of partialCached lets it build 5,000+ pages in 20 seconds.



Template Metrics:

     cumulative       average       maximum         
       duration      duration      duration  count  template
     ----------      --------      --------  -----  --------
  59m18.008467032s  391.377017ms  867.537739ms   9091  _default/tag.html
  18m37.624437756s    1.424335ms  174.518125ms  784664  _default/rss.xml
  43.361296251s   25.357483ms  162.020332ms   1710  _default/single.html
  41.696158265s    3.828496ms  120.477366ms  10891  partials/sidebar.html
   21.97402185s    2.017631ms   91.443604ms  10891  partials/_widgets/recent_posts.html
  17.564270709s    1.612732ms   102.02018ms  10891  partials/_widgets/category.html
   9.775841656s     897.607µs   56.706936ms  10891  partials/header.html
    8.14678649s     748.029µs   94.097839ms  10891  partials/head.html
   7.955968046s    4.652612ms  129.357721ms   1710  partials/article.html
   7.411152815s  130.020224ms  226.438422ms     57  index.html
   7.145596414s     257.276µs   74.053796ms  27774  partials/card-post.html
   6.949008149s  6.949008149s  6.949008149s      1  _default/list.searchindex.json
   4.610428181s    2.696156ms  125.093995ms   1710  partials/related.html
   4.393994301s  4.393994301s  4.393994301s      1  _default/tag.terms.html
   3.618406424s     332.238µs   45.253596ms  10891  partials/script.html
   2.992701514s   52.503535ms  125.020011ms     57  partials/post/stiky.html
   2.609665929s     239.616µs    99.72264ms  10891  partials/footer.html
   2.589817147s     757.035µs    52.69412ms   3421  partials/post/wc.html
   1.324610697s     121.624µs   99.669698ms  10891  partials/social.html
   727.861966ms   31.646172ms  140.784795ms     23  _default/category.html
   563.362425ms      51.727µs   85.409156ms  10891  partials/_widgets/board.html
   548.829515ms      50.392µs   45.696666ms  10891  partials/search.html
   548.420823ms      64.573µs    41.88207ms   8493  partials/item-post.html
   521.679181ms       57.17µs   71.440983ms   9125  _internal/alias.html
    479.59484ms       280.3µs   31.091737ms   1711  partials/post/tag.html
   420.651968ms  420.651968ms  420.651968ms      1  _default/category.terms.html
   415.537993ms  415.537993ms  415.537993ms      1  _default/sitemap.xml
   382.562636ms      223.72µs   19.281295ms   1710  partials/post/nav.html
   372.705603ms      34.221µs   21.338629ms  10891  partials/_script/analytics.html
   347.774519ms     101.658µs     30.0802ms   3421  partials/post/date.html
   337.981089ms   48.283012ms  249.750304ms      7  _default/list.html
   337.114977ms      98.542µs    23.28851ms   3421  partials/post/category.html
   317.465365ms     185.543µs   25.176684ms   1711  partials/post/copyright.html
   207.020335ms     120.993µs   44.221691ms   1711  partials/post/pv.html
   181.047131ms      107.83µs   45.034704ms   1679  partials/_script/comment.html
   142.343741ms      83.241µs   23.623213ms   1710  partials/post/title.html
   100.784335ms      58.938µs   14.709665ms   1710  partials/_script/pv.html
    88.224797ms      51.563µs   18.362587ms   1711  partials/post/comment.html
    80.477974ms      47.063µs   14.785213ms   1710  partials/post/title-post.html
    58.459154ms      34.186µs    5.518728ms   1710  partials/sidebar-toc.html
     30.47743ms       2.798µs    17.27827ms  10891  partials/_script/fancybox.html
    21.371758ms       12.49µs    2.980391ms   1711  partials/post/donate.html
    15.075657ms   15.075657ms   15.075657ms      1  404.html
     9.407409ms     165.042µs    3.401523ms     57  partials/pagination.html
     1.959751ms       1.146µs     163.981µs   1710  partials/post/gallery.html
        3.629µs       3.629µs       3.629µs      1  robots.txt

                   |   ZH    
  Pages            |  19961  
  Paginator pages  | 775596  
  Non-page files   |      0  
  Static files     |     22  
  Processed images |      0  
  Aliases          |   9125  
  Sitemaps         |      1  
  Cleaned          |      0  

Total in 486567 ms

Please help

You build a lot of pagination … And it seems to be tag related. How does your tag templates look like?

1 Like


{{- with .Params.tags}}  
  <span class="article-tag">
    <i class="icon icon-tags"></i>
    {{- range . }}
    <a class="article-tag-link" href="{{ "tags" | relLangURL }}/{{ . | urlize }}/"> {{ . }} </a>
    {{- end}}
{{- end }} 

What happens if you eliminate the RSS feeds for each taxonomy tag? It’s unlikely that there’s a big demand for subscribing to each tag. From my config.toml:

home = ["HTML","RSS"]
page = ["HTML"]
section = ["HTML"]
taxonomy = ["HTML"]
taxonomyTerm = ["HTML"]

You could also try disabling pagination on specific templates by adding a comment at the top. You’ve got hundreds of thousands of paginator pages that I don’t think you want:

<!--{{ .Paginator 9999 }}-->

Given the small number of actual posts, I think the root cause is that you have a very large list of tags with several of them applied to each post (hence the 0.4-second average time for _default/tag.html). Having a large number of distinct terms in a taxonomy can significantly increase build time, although Hugo has gotten a lot faster since I last tested it with 100,000+ posts.


You shared the contents of layouts/partials/post/tag.html, but that’s not the layout that’s killing you:

      cumulative       average       maximum         
        duration      duration      duration  count  template
      ----------      --------      --------  -----  --------
59m18.008467032s  391.377017ms  867.537739ms   9091  _default/tag.html
     479.59484ms       280.3µs   31.091737ms   1711  partials/post/tag.html

We would need to see the contents of layouts/_default/tag.html.