Extremely slow dev server

I’m in the process of upgrading from 0.119.x to 0.142.0 (finally). When running hugo I get build times similar to what I’ve been getting on 0.119, however when running hugo server, it’s taking around 16mins to build before the live server starts.

I unfortunately can’t share the repo as it’s private. I would attempt to reproduce in a demo, but I don’t really know where to start.

Are there areas to which I should pay particular attention that could be the culprit in this massive build time difference?

Run the server with --templateMetrics and --templateMetricsHints and identify the layout files that slow things down. In my experience it’s image processing (do not delete/ignore resources folder after one initial slow run) and pager for list pages (use higher limits for the displayed items per page).

Sorry for the off-topic question, but how many pages does your site have? 16 minutes seems too long to me, especially when Hugo is claimed to be the fastest SSG on the market.

You need to provide much better information about your site. There’s no way anyone can guess bassed in the few sentecnes you’ve given.

Thanks, @davidsneighbour! I don’t think it’s a general layout performance issue since running a build without using the dev server (i.e. hugo) is completing in a reasonable, expected amount of time. It’s only when running the dev server that I get the unusually long build times. I’m also not getting the same disparate build times in 0.119.x.

You need to provide much better information about your site.

I’d be glad to, but I’m not really certain where to start. Potentially relevant parts of the puzzle that come to mind:

  • Stylesheets use Sass and toCSS (configured for Dart Sass) for transformation.
  • I’m using Tailwind 3.x via postCSS
  • My primary stylesheet loading looks like the below:
{{- $css := resources.Get "scss/main.scss" | toCSS (merge $toCSSOptions (dict "targetPath" "static-assets/css/main.css")) | postCSS $postCSSOptions -}}
{{- if not hugo.IsDevelopment -}}
    {{ $css = $css | minify | fingerprint }}
{{- end -}}
{{ with $css }}
  {{ if not hugo.IsDevelopment }}
    <link href="{{ .RelPermalink }}" rel="stylesheet" data-integrity="{{ .Data.Integrity }}" />
  {{ else }}
    <link href="{{ .RelPermalink }}" rel="stylesheet" />
  {{ end }}
{{ end }}

{{ with .CurrentSection.Resources.GetMatch "styles.section.{scss,css}" }}
    {{- $sectionCSS := . | toCSS $toCSSOptions | postCSS $postCSSOptions -}}
    {{- if not hugo.IsDevelopment -}}
        {{ $sectionCSS = $sectionCSS | minify | fingerprint }}
    {{- end -}}
    {{ with $sectionCSS }}
      {{ if not hugo.IsDevelopment }}
        <link href="{{ .RelPermalink }}" rel="stylesheet" data-integrity="{{ .Data.Integrity }}" />
      {{ else }}
        <link href="{{ .RelPermalink }}" rel="stylesheet" />
      {{ end }}
    {{ end }}
{{ end }}

{{ with .Resources.GetMatch "styles.{scss,css}" }}
    {{- $pageCSS := . | toCSS $toCSSOptions | postCSS $postCSSOptions -}}
    {{- if not hugo.IsDevelopment -}}
        {{ $pageCSS = $pageCSS | minify | fingerprint }}
    {{- end -}}
    {{ with $pageCSS }}
      {{ if not hugo.IsDevelopment }}
        <link href="{{ .RelPermalink }}" rel="stylesheet" data-integrity="{{ .Data.Integrity }}" />
      {{ else }}
        <link href="{{ .RelPermalink }}" rel="stylesheet" />
      {{ end }}
    {{ end }}
{{ end }}
  • Javascript is transpiled using js.Build (with minification for production builds). fingerprint is used for production builds as well (using the same conditional logic as the CSS above).

Below are the stats when completing a build (without the dev server):

|  EN  | EN-IN |  JA  |  ZH  |  KO  |  DE  |  FR  |  ES  |  DA  |  IT  | PT-BR |  SV  | FIL  |  HI  |  ID  |  NL  |  PL  |  RU  |  VI  |  CA  |  RO  |  TR  |  UK
-------------------+------+-------+------+------+------+------+------+------+------+------+-------+------+------+------+------+------+------+------+------+------+------+------+-------
  Pages            | 1145 |   181 |  336 |  102 |  104 |  117 |  117 |  322 |    7 |   28 |   164 |    7 |   27 |   27 |   28 |   27 |   27 |   28 |   27 |   81 |   83 |   28 |   26
  Paginator pages  |   49 |     2 |   16 |    0 |    0 |    0 |    0 |    0 |    0 |    0 |     0 |    0 |    0 |    0 |    0 |    0 |    0 |    0 |    0 |    0 |    0 |    0 |    0
  Non-page files   | 2656 |   366 | 1050 |  338 |  357 |  419 |  419 |  536 |   34 |  182 |   309 |   34 |  182 |  182 |  201 |  182 |  182 |  201 |  182 |  357 |  375 |   80 |   70
  Static files     | 2556 |  2556 | 2556 | 2556 | 2556 | 2556 | 2556 | 2556 | 2556 | 2556 |  2556 | 2556 | 2556 | 2556 | 2556 | 2556 | 2556 | 2556 | 2556 | 2556 | 2556 | 2556 | 2556
  Processed images |   18 |     0 |    0 |    0 |    0 |    0 |    0 |    0 |    0 |    0 |     0 |    0 |    0 |    0 |    0 |    0 |    0 |    0 |    0 |    0 |    0 |    0 |    0
  Aliases          |   26 |    12 |   27 |   10 |   10 |   13 |   13 |   17 |    1 |    1 |    12 |    1 |    2 |    2 |    2 |    1 |    1 |    2 |    2 |   19 |   18 |    7 |    7
  Cleaned          |    0 |     0 |    0 |    0 |    0 |    0 |    0 |    0 |    0 |    0 |     0 |    0 |    0 |    0 |    0 |    0 |    0 |    0 |    0 |    0 |    0 |    0 |    0

What other information would be useful?

Thank you!

Operating system?

macOS 15.3

How big are your “static files”? Could you try starting the server without the static directory? (e.g. renaming it to something else).

Tried renaming the static folder, but the initial build for starting the dev server still took ~15mins.

The static folder is about 144.5MB. The largest file is about 27MB, second largest is 10.25MB, 23 files are between 1MB and 8MB, and the remaining ~5,000 files are under 1MB.

just like digging in the dark…

the full logfile for a second eye to look on may reveal some hidden insights. share it.

just thinking out loud:

large json datasets you are manipulating? map merges? os.Readfile and evaluating content? complex templates with lot of code?

whats after the initial run. stop server and next will be fast?

clear all caches and start with fresh clone

hw? disk? memory?

segments config might help to pinpoint.

running hugo server with the production environment also slow? what differences in config between additionally to the above.

any sourrounding steps or really just call hugo

maybe build on another machine. maybe clear all hugo caches, and start with a fresh clone…

.a second foreign build and check might be helpful…

impossible to track that down without access

you can share privately by temporary add read access…

OK, can you post the output of the starting the server with hugo server --logLevel info in here?

Thank you all for your continued assistance.

@bep, here’s a Gist with the output for hugo server --logLevel info:
https://gist.githubusercontent.com/AlanBreck/4b404a0d17156c3dbc2347dd6904e86e/raw/44db4626077656cbd7e5b99873b577125788c40a/output.txt

@irkode, here’s a Gist with the output from hugo server --templateMetrics --templateMetricsHints --logLevel debug
https://gist.githubusercontent.com/AlanBreck/4b404a0d17156c3dbc2347dd6904e86e/raw/44db4626077656cbd7e5b99873b577125788c40a/output-verbose.txt

whats after the initial run. stop server and next will be fast?

Unfortunately, it’s no different when running, stopping, and then starting again.

I see lots of lines like this in your log:

INFO  dynacache: adjusted partitions' max size evicted 748 numGC 94 limit 4.00 GB alloc 4.15 GB totalAlloc 25.80 GB

Can you:

  1. Check if you see simllar log lines when running hugo --logLevel info?
  2. Can you try to set Hugo’s memory limit to something bigger and try again., e.g.export HUGO_MEMORYLIMIT=8 and try again (8 GB).

I don’t have a good explanation as to why this happens in the server and not when building, but there’s something that “eats” memory somewhere, and that makes the cache much less useful.

yepp and a lot of memory consumption >30GB - what about Stats while processing? CPU Cores, MEM

I see lots of postcss complains - and supposedly 14 executions what happens if you skip that, and maybe minimize.

reminds me, there where more points in my post - machine stats, mem, …

what about comparing the results of using hugo server and hugo with any config

* `hugo --environment development`
* `hugo --environment production`            <-- default
* `hugo server --environment production`
* `hugo server --environment development`    <-- default
  • a line like that:

    INFO  build:  step render substep pages site ro outputFormat html duration 3m6.198061375s
    

    with 3.5 min for 83 pages seems at least unusual.

  • with template metrics you have
    for example >100.000 calls to GetLink which sum up to a minute…

  • you have much more pages and files in EN site do you merge missing pages…

all that said:

I think that all (and things we do not know) play together to get such a result

imho that won’t work out here with some extracts from your site and log files… one who is willing to analyze and pin that down needs a full repo to do.

As to TailwindCSS, I would highly recommend to upgrade to TailwindCSS v4 (recently released) and use the setup as outlined in: