# Benchmarking and improving theme

**URL:** <https://discourse.gohugo.io/t/benchmarking-and-improving-theme/10138>\
**Category:** support\
**Created:** [January 22, 2018, 4:27pm UTC](https://discourse.gohugo.io/t/benchmarking-and-improving-theme/10138 "2018-01-22T16:27:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![brunoamaral](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/brunoamaral/32/21144_2.png) [@brunoamaral](https://discourse.gohugo.io/u/brunoamaral)\
**Post date:** [January 22, 2018, 4:27pm UTC](https://discourse.gohugo.io/t/benchmarking-and-improving-theme/10138/1 "2018-01-22T16:27:19Z")

</div>

I am having some trouble understanding how to evaluate the speed at which hugo is processing my theme and content.

My theme is taking over a minute to render the whole site, and I am guessing it has a lot to do with the way that I ported the theme. What sort of bottlenecks should I be looking for here?

```
hugo --stepAnalysis --templateMetrics --templateMetricsHints
Building sites … initialize:
	375.075305ms (378.858036ms) 11.59 MB 170803 Allocs
load data:
	53.786µs (379.35551ms) 0.00 MB 30 Allocs
load i18n:
	481ns (379.693721ms) 0.00 MB 0 Allocs
read and convert pages from source:
	7.310749924s (7.691075576s) 173.03 MB 669815 Allocs
build Site meta:
	17.816172ms (7.710325873s) 2.14 MB 33738 Allocs
build Site meta:
	156.963µs (7.710826818s) 0.01 MB 282 Allocs
prepare pages:
	150.773616ms (7.862051436s) 16.42 MB 130664 Allocs
render and write aliases:
	3.921725ms (7.866339263s) 0.07 MB 1143 Allocs
render and write pages:
	1m2.797401315s (1m10.664276911s) 4382.27 MB 125343410 Allocs
render and write Sitemap:
	103.26934ms (1m10.768118153s) 8.32 MB 169158 Allocs
render and write robots.txt:
	10.695µs (1m10.768454049s) 0.00 MB 9 Allocs
render and write 404:
	2.328271ms (1m10.771097784s) 0.18 MB 3896 Allocs
render and write pages:
	546.344392ms (1m11.317890031s) 39.98 MB 676708 Allocs
prepare pages:
	5.059981ms (1m11.323438908s) 0.81 MB 3889 Allocs
render and write aliases:
	153.123µs (1m11.323910706s) 0.00 MB 83 Allocs
render and write pages:
	194.8843ms (1m11.519268279s) 19.78 MB 407677 Allocs
render and write Sitemap:
	2.101481ms (1m11.521804288s) 0.11 MB 2984 Allocs
render and write robots.txt:
	9.156µs (1m11.522121576s) 0.00 MB 9 Allocs
render and write 404:
	2.242685ms (1m11.524683485s) 0.22 MB 4517 Allocs
render and write pages:
	12.418712ms (1m11.537455658s) 1.48 MB 22999 Allocs

Template Metrics:

      cache cumulative average maximum
  potential duration duration duration count template
      ----- ---------- -------- -------- ----- --------
          0 55.132258005s 33.78202ms 205.23696ms 1632 theme/index.html
          2 25.189533903s 15.434763ms 127.712522ms 1632 theme/partials/highlighted_stories.html
          0 16.336586781s 11.553455ms 436.722981ms 1414 theme/instagram/instagram.html
          0 11.653866557s 52.026189ms 142.727581ms 224 theme/unlisted/list.html
          0 8.76427927s 46.127785ms 140.411721ms 190 theme/taxonomy/category.html
         16 7.965004571s 1.906415ms 121.121438ms 4178 theme/partials/header.html
         99 5.376794695s 1.28693ms 280.713818ms 4178 theme/partials/top_navigation.html
          0 4.923603536s 18.440462ms 203.611115ms 267 theme/_default/single.html
          9 4.53370277s 1.085137ms 113.348541ms 4178 theme/partials/footer.html
          0 3.7483809s 9.969098ms 122.991214ms 376 theme/taxonomy/tag.html
          0 2.665127388s 691.343µs 141.722216ms 3855 theme/_default/summary.html
          0 1.430422874s 3.480347ms 271.878297ms 411 _internal/_default/rss.xml
          0 998.322939ms 353.138µs 80.866129ms 2827 theme/instagram/summary.html
          0 801.038546ms 47.119914ms 363.680654ms 17 theme/_default/page.html
         98 775.517042ms 185.619µs 153.993637ms 4178 theme/partials/footer-links.html
         49 727.285192ms 175.165µs 80.74329ms 4152 theme/partials/pagination.html
          0 535.152793ms 327.912µs 54.72669ms 1632 theme/_default/li.html
          0 530.36221ms 25.255343ms 134.288832ms 21 theme/taxonomy/story.html
          0 497.574862ms 497.574862ms 497.574862ms 1 json/single.html
          0 388.097899ms 24.256118ms 145.853154ms 16 theme/post/list.html
          0 369.434425ms 184.717212ms 368.027556ms 2 theme/rss.xml
         99 333.729283ms 135.717µs 80.799148ms 2459 theme/partials/title_section.html
          0 326.269153ms 54.378192ms 138.570776ms 6 theme/_default/terms.html
          0 211.80755ms 17.650629ms 65.327047ms 12 theme/_default/list.html
          0 154.525467ms 154.525467ms 154.525467ms 1 theme/unlisted/unlistedarticles.html
          0 100.644679ms 50.322339ms 98.716539ms 2 theme/sitemap.xml
          0 12.755698ms 283.459µs 1.852894ms 45 _internal/shortcodes/tweet.html
          0 9.069248ms 89.794µs 475.301µs 101 theme/shortcodes/galleryimage.html
          0 4.268484ms 2.134242ms 2.146428ms 2 theme/404.html
        100 2.657721ms 1.559µs 92.381µs 1704 theme/partials/googletagmanager.html
          0 1.253147ms 73.714µs 376.013µs 17 _internal/shortcodes/youtube.html
          0 407.928µs 407.928µs 407.928µs 1 _internal/_default/sitemapindex.xml
          0 228.985µs 228.985µs 228.985µs 1 theme/shortcodes/text
          0 224.494µs 28.061µs 71.113µs 8 theme/shortcodes/gallery.html
          0 203.526µs 25.44µs 122.09µs 8 theme/shortcodes/galleryinit.html
          0 89.73µs 89.73µs 89.73µs 1 theme/shortcodes/text.html

                   | EN | PT
+------------------+------+------+
  Pages | 2477 | 49
  Paginator pages | 2047 | 19
  Non-page files | 2804 | 1297
  Static files | 764 | 764
  Processed images | 0 | 0
  Aliases | 408 | 12
  Sitemaps | 2 | 1
  Cleaned | 0 | 0

Total in 71539 ms
```

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [January 22, 2018, 4:49pm UTC](https://discourse.gohugo.io/t/benchmarking-and-improving-theme/10138/2 "2018-01-22T16:49:35Z")

</div>

> [@brunoamaral](#):
>
> 0 55.132258005s 33.78202ms 205.23696ms 1632 theme/index.html

You render your home page tempalte 1632 times, which does not make much sense to me.

But you need to link to the source if you want any more than guesses.

---

<div class="post-metadata">

**Author:** ![brunoamaral](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/brunoamaral/32/21144_2.png) [@brunoamaral](https://discourse.gohugo.io/u/brunoamaral)\
**Post date:** [January 22, 2018, 4:59pm UTC](https://discourse.gohugo.io/t/benchmarking-and-improving-theme/10138/3 "2018-01-22T16:59:03Z")

</div>

thanks for the quick reply @bep

I don’t see why that could happen, and i do have the theme published here: [https://github.com/brunoamaral/future-imperfect-DI](https://github.com/brunoamaral/future-imperfect-DI)

I was actually thinking that in some cases I may have unnecessary IFs and ranges. One of which I was able to solve in another thread and bring the build time down by 30 seconds.

---

<div class="post-metadata">

**Author:** ![jgreely](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jgreely/32/6796_2.png) [@jgreely](https://discourse.gohugo.io/u/jgreely)\
**Post date:** [January 22, 2018, 6:10pm UTC](https://discourse.gohugo.io/t/benchmarking-and-improving-theme/10138/4 "2018-01-22T18:10:38Z")

</div>

> [@bep](#):
>
> You render your home page tempalte 1632 times, which does not make much sense to me.

He’s paginating the home page with 1 article per page, but never actually using the resulting pages. The “older posts” button uses the `post` section’s pagination, so the actual navigation is `/post/page/N/` instead of `/page/N/`.

themes/future-imperfect-DI/layouts/index.html:

```auto
{{ $loop := (.Paginate (where (where .Data.Pages "Type" "!=" "page") ".Params.unlisted" "!=" true ) 1).Pages }}

```

-j

---

<div class="post-metadata">

**Author:** ![brunoamaral](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/brunoamaral/32/21144_2.png) [@brunoamaral](https://discourse.gohugo.io/u/brunoamaral)\
**Post date:** [January 22, 2018, 6:59pm UTC](https://discourse.gohugo.io/t/benchmarking-and-improving-theme/10138/5 "2018-01-22T18:59:48Z")

</div>

thanks for noticing @jgreely !

I rewrote that bit like this:

```
{{ $loop := (where (where .Data.Pages "Type" "!=" "page") ".Params.unlisted" "!=" true ) }}

{{ partial "highlighted_stories.html" . }}
{{ range first 1 $loop }}
	{{ .Render "li" }}
{{ end }}

```

and it was quite an improvement:

Template Metrics:

```
    cache cumulative average maximum
potential duration duration duration count template
    ----- ---------- -------- -------- ----- --------
        0 3.726837651s 21.922574ms 35.990012ms 170 theme/index.html
        0 3.232025681s 14.428686ms 27.236281ms 224 theme/unlisted/list.html
        0 2.869832202s 2.029584ms 13.439723ms 1414 theme/instagram/instagram.html
        0 1.960847269s 10.320248ms 22.892158ms 190 theme/taxonomy/category.html
        2 1.709990299s 10.058766ms 20.857199ms 170 theme/partials/highlighted_stories.html
       17 1.398096264s 514.762µs 10.552804ms 2716 theme/partials/header.html
        0 1.001004224s 3.749079ms 13.941071ms 267 theme/_default/single.html
       30 978.342598ms 360.214µs 3.712955ms 2716 theme/partials/footer.html
        0 922.003314ms 2.452136ms 8.794505ms 376 theme/taxonomy/tag.html
       99 824.992481ms 303.752µs 2.427806ms 2716 theme/partials/top_navigation.html
        0 530.574737ms 137.632µs 2.360128ms 3855 theme/_default/summary.html
        0 233.245793ms 567.508µs 51.244149ms 411 _internal/_default/rss.xml
        0 219.302372ms 77.574µs 745.363µs 2827 theme/instagram/summary.html
       98 125.162028ms 46.083µs 2.818259ms 2716 theme/partials/footer-links.html
       76 106.003182ms 39.406µs 1.194178ms 2690 theme/partials/pagination.html
        0 101.069168ms 16.844861ms 35.570206ms 6 theme/_default/terms.html
        0 94.283844ms 94.283844ms 94.283844ms 1 json/single.html
        0 73.422806ms 4.588925ms 8.208275ms 16 theme/post/list.html
        0 67.582229ms 3.218201ms 4.633659ms 21 theme/taxonomy/story.html
        0 65.958024ms 32.979012ms 65.038728ms 2 theme/rss.xml
        0 64.697512ms 32.348756ms 63.631871ms 2 theme/sitemap.xml
       99 56.037085ms 56.205µs 493.041µs 997 theme/partials/title_section.html
        0 54.010464ms 4.500872ms 11.860365ms 12 theme/_default/list.html
        0 40.574634ms 2.386743ms 4.85888ms 17 theme/_default/page.html
        0 33.652659ms 197.956µs 1.515437ms 170 theme/_default/li.html
        0 14.298039ms 14.298039ms 14.298039ms 1 theme/unlisted/unlistedarticles.html
      100 7.074683ms 4.151µs 408.489µs 1704 theme/partials/googletagmanager.html
        0 6.804792ms 151.217µs 503.893µs 45 _internal/shortcodes/tweet.html
        0 6.506568ms 64.421µs 215.371µs 101 theme/shortcodes/galleryimage.html
        0 2.55309ms 1.276545ms 1.486006ms 2 theme/404.html
        0 757.614µs 44.565µs 222.127µs 17 _internal/shortcodes/youtube.html
        0 317.925µs 317.925µs 317.925µs 1 _internal/_default/sitemapindex.xml
        0 309.645µs 309.645µs 309.645µs 1 theme/shortcodes/text
        0 278.935µs 34.866µs 89.011µs 8 theme/shortcodes/gallery.html
        0 197.735µs 24.716µs 115.99µs 8 theme/shortcodes/galleryinit.html
        0 91.401µs 91.401µs 91.401µs 1 theme/shortcodes/text.html

                     | EN | PT
  +------------------+------+------+
    Pages | 2477 | 49
    Paginator pages | 600 | 4
    Non-page files | 2804 | 1297
    Static files | 766 | 766
    Processed images | 0 | 0
    Aliases | 408 | 12
    Sitemaps | 2 | 1
    Cleaned | 0 | 0

  Total in 7272 ms
```
