Would make slower when with `-` character in hugo snippet?

Hi guys:

As we known Hugo snippet support use - character trim space, it’s useful generate pretty code of HTML. But I want to know is there will make hugo generate site static code more slower?

As below code sample:


Question: Those code with - character will make generate speed more slower?

How about your think?

Have never noticed any difference, and that’s in a repository with hundreds of files.

Not yeah, the theme source files is small under hundred, but if the content files of blog articles too much, I think the generate speed would be slow down.

But I don’t know about Go language, so can’t make sure is the block {{- /* Some logic */ -}} slower than {{/* Some logic */}} , maybe some can help me find the answer, thanks.

I wrote a simple benchmark.

var t1 = template.Must(template.New("t1").Parse(`"{{23 }} < {{ 45}}"`))
var t2 = template.Must(template.New("t2").Parse(`"{{23 -}} < {{- 45}}"`))
✗ go test -bench .
goos: linux
goarch: amd64
pkg: github.com/razonyang/go-lab
cpu: 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
BenchmarkT1-16            688731              1590 ns/op
BenchmarkT2-16            649561              1649 ns/op
PASS
ok      github.com/razonyang/go-lab     2.208s
✗ go test -bench .
goos: linux
goarch: amd64
pkg: github.com/razonyang/go-lab
cpu: 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
BenchmarkT1-16            693091              1619 ns/op
BenchmarkT2-16            699934              1642 ns/op
PASS
ok      github.com/razonyang/go-lab     2.312s
✗ go test -bench .
goos: linux
goarch: amd64
pkg: github.com/razonyang/go-lab
cpu: 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
BenchmarkT1-16            705924              1639 ns/op
BenchmarkT2-16            701492              1633 ns/op
PASS
ok      github.com/razonyang/go-lab     2.342s
✗ go test -bench .
goos: linux
goarch: amd64
pkg: github.com/razonyang/go-lab
cpu: 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
BenchmarkT1-16            692338              1602 ns/op
BenchmarkT2-16            688156              1582 ns/op
PASS
ok      github.com/razonyang/go-lab     2.238s
✗ go test -bench .
goos: linux
goarch: amd64
pkg: github.com/razonyang/go-lab
cpu: 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
BenchmarkT1-16            695038              1614 ns/op
BenchmarkT2-16            590240              1712 ns/op
PASS
ok      github.com/razonyang/go-lab     2.175s

Less ns/op are better.

Source code could be found at GitHub - razonyang/go-lab: NOTHING HERE.

1 Like

The difference in build time is noise.

I have a 10,000 page site. Each page is rendered by layouts/_default/single.html, which has 100 of these:

{{- if true -}}

  {{- .Title -}}

{{- end -}}

That’s 3 million of these {{- and another 3 million of these -}}.

I built the 5 site times, with and without whitespace removal.

  With {{ }} With {{- -}}
Minimum 4875 ms 4891 ms
Maximum 5201 ms 5676 ms
Average 5015 ms 5111 ms
2 Likes

@razon @jmooring
Thanks for your code, there look seems the code block of {{/*some logic*/}} were more better. But not matter it’s smaller different not much effect.

Hope this post would help more people who notice the generate speed under Hugo engine.

1 Like