HUGO

  • News
  • Docs
  • Themes
  • Showcase
  • Community
  • GitHub
gohugoio Star
  • About Hugo
    • Overview
    • What is Hugo
    • Hugo features
    • Static site generators
    • Hugo's security model
    • Hugo and the GDPR
    • License
  • Installation
    • Overview
    • macOS
    • Linux
    • Windows
    • BSD
  • Getting started
    • Overview
    • Quick start
    • Basic usage
    • Directory structure
    • Configuration
    • Configure markup
    • Glossary of terms
    • External learning resources
  • Quick reference
    • Overview
    • Emojis
    • Functions
    • Methods
    • Page collections
  • Content management
    • Overview
    • Organization
    • Page bundles
    • Content formats
    • Front matter
    • Build options
    • Page resources
    • Image processing
    • Shortcodes
    • Related content
    • Sections
    • Content types
    • Archetypes
    • Taxonomies
    • Summaries
    • Links and cross references
    • URL management
    • Menus
    • Static files
    • Table of contents
    • Comments
    • Multilingual
    • Markdown attributes
    • Syntax highlighting
    • Diagrams
    • Mathematics
  • Templates
    • Overview
    • Templating
    • Template lookup order
    • Base templates and blocks
    • Single page templates
    • List templates
    • Homepage template
    • Section templates
    • Taxonomy templates
    • Pagination
    • Content view templates
    • Partial templates
    • Shortcode templates
    • Menu templates
    • Data templates
    • RSS templates
    • Sitemap templates
    • Internal templates
    • Custom output formats
    • 404 page
    • Robots.txt
  • Functions
    • Overview
    • cast
    • collections
    • compare
    • crypto
    • data
    • debug
    • diagrams
    • encoding
    • fmt
    • global
    • go template
    • hugo
    • images
    • inflect
    • js
    • lang
    • math
    • openapi3
    • os
    • partials
    • path
    • reflect
    • resources
    • safe
    • strings
    • templates
    • time
    • transform
    • urls
  • Methods
    • Overview
    • Duration
    • Menu
    • Menu entry
    • Page
    • Pages
    • Resource
    • Shortcode
    • Site
    • Taxonomy
    • Time
  • Render hooks
    • Overview
    • Introduction
    • Code blocks
    • Headings
    • Images
    • Links
  • Hugo Modules
    • Overview
    • Configure Hugo modules
    • Use Hugo Modules
    • Theme components
  • Hugo Pipes
    • Overview
    • Introduction
    • Transpile Sass to CSS
    • PostCSS
    • PostProcess
    • JavaScript building
    • Babel
    • Asset minification
    • Concatenating assets
    • Fingerprinting and SRI hashing
    • Resource from string
    • Resource from template
  • CLI
  • Troubleshooting
    • Overview
    • Audit
    • Logging
    • Inspection
    • Deprecation
    • Performance
    • FAQs
  • Developer tools
    • Overview
    • Editor plugins
    • Front-ends
    • Search
    • Migrations
    • Other projects
  • Hosting and deployment
    • Overview
    • Hugo Deploy
    • Deploy with Rclone
    • Deploy with Rsync
    • Host on 21YunBox
    • Host on AWS Amplify
    • Host on Azure Static Web Apps
    • Host on Cloudflare Pages
    • Host on Firebase
    • Host on GitHub Pages
    • Host on GitLab Pages
    • Host on KeyCDN
    • Host on Netlify
    • Host on Render
  • Contribute
    • Overview
    • Development
    • Documentation
    • Themes
  • Maintenance
TROUBLESHOOTING

Performance

Use template metrics and timers to identify opportunities to improve performance.

Template metrics

Hugo is fast, but inefficient templates impede performance. Enable template metrics to determine which templates take the most time, and to identify caching opportunities:

hugo --templateMetrics --templateMetricsHints

The result will look something like this:

Template Metrics:

     cumulative       average       maximum      cache  percent  cached  total  
       duration      duration      duration  potential   cached   count  count  template
     ----------      --------      --------  ---------  -------  ------  -----  --------
  36.037476822s  135.990478ms  225.765245ms         11        0       0    265  partials/head.html
  35.920040902s  164.018451ms  233.475072ms          0        0       0    219  articles/single.html
  34.163268129s  128.917992ms  224.816751ms         23        0       0    265  partials/head/meta/opengraph.html
   1.041227437s     3.92916ms  186.303376ms         47        0       0    265  partials/head/meta/schema.html
   805.628827ms   27.780304ms  114.678523ms          0        0       0     29  _default/list.html
    624.08354ms   15.221549ms  108.420729ms          8        0       0     41  partials/utilities/render-page-collection.html
   545.968801ms     775.523µs  105.045775ms          0        0       0    704  _default/summary.html
   334.680981ms    1.262947ms  127.412027ms        100        0       0    265  partials/head/js.html
   272.763205ms    2.050851ms   24.371757ms          0        0       0    133  _default/_markup/render-codeblock.html
   230.490038ms    8.865001ms    177.4615ms          0        0       0     26  shortcodes/template.html
   176.921913ms  176.921913ms  176.921913ms          0        0       0      1  examples.tmpl
   163.951469ms   14.904679ms   70.267953ms          0        0       0     11  articles/list.html
    153.07021ms     577.623µs   73.593597ms        100        0       0    265  partials/head/init.html
   150.910984ms  150.910984ms  150.910984ms          0        0       0      1  _default/single.html
   146.785804ms  146.785804ms  146.785804ms          0        0       0      1  _default/contact.html
   115.364617ms  115.364617ms  115.364617ms          0        0       0      1  authors/term.html
    87.392071ms     329.781µs   10.687132ms        100        0       0    265  partials/head/css.html
    86.803122ms   86.803122ms   86.803122ms          0        0       0      1  _default/home.html

From left to right, the columns represent:

cumulative duration
The cumulative time spent executing the template.
average duration
The average time spent executing the template.
maximum duration
The maximum time spent executing the template.
cache potential
Displayed as a percentage, any partial template with a 100% cache potential should be called with the partialCached function instead of the partial function. See the caching section below.
percent cached
The number of times the rendered templated was cached divided by the number of times the template was executed.
cached count
The number of times the rendered templated was cached.
total count
The number of times the template was executed.
template
The path to the template, relative to the layouts directory.

Hugo builds pages in parallel where multiple pages are generated simultaneously. Because of this parallelism, the sum of “cumulative duration” values is usually greater than the actual time it takes to build a site.

Caching

Some partial templates such as sidebars or menus are executed many times during a site build. Depending on the content within the partial template and the desired output, the template may benefit from caching to reduce the number of executions. The partialCached template function provides caching capabilities for partial templates.

Note that you can create cached variants of each partial by passing additional parameters to partialCached beyond the initial context. See the partialCached documentation for more details.

Timers

Use the debug.Timer function to determine execution time for a block of code, useful for finding performance bottle necks in templates. See details.

See also

  • Hugo Pipes
  • resources.GetRemote

On this page

  • Template metrics
  • Caching
  • Timers
Last updated: February 3, 2024: Replace links to variable pages with links to method pages (126c323d)
Improve this page
By the Hugo Authors
Hugo Logo
  • File an Issue
  • Get Help
  • @GoHugoIO
  • @spf13
  • @bepsays

Netlify badge

 

Hugo Sponsors

 

The Hugo logos are copyright © Steve Francia 2013–2024.

The Hugo Gopher is based on an original work by Renée French.

  • News
  • Docs
  • Themes
  • Showcase
  • Community
  • GitHub
  • About Hugo
  • Installation
  • Getting started
  • Quick reference
  • Content management
  • Templates
  • Functions
  • Methods
  • Render hooks
  • Hugo Modules
  • Hugo Pipes
  • CLI
  • Troubleshooting
  • Developer tools
  • Hosting and deployment
  • Contribute
  • Maintenance