@bep,
I may be out of my depth here, but…
I was looking over the memory profiler results of building the Hugo docs site and noticed that about 10% of the cumulative memory space is used by the return value of templateHandler.LookupVariant
.
Would it be feasible to return a pointer here or do we need a new copy of the template each time?
$ go test -run=NONE -bench=. -benchmem -memprofile mem.prof -memprofilerate 1 .
$ go tool pprof hugo.test mem.prof
(pprof) tree
Showing nodes accounting for 297427.17kB, 46.15% of 644411.12kB total
Dropped 2282 nodes (cum <= 3222.05kB)
Showing top 80 nodes out of 280
----------------------------------------------------------+-------------
flat flat% sum% cum cum% calls calls% + context
----------------------------------------------------------+-------------
63386.59kB 97.34% | github.com/gohugoio/hugo/hugolib.(*pageState).resolveTemplate
1490.34kB 2.29% | golang.org/x/sync/errgroup.(*Group).Go.func1
77.03kB 0.012% 37.49% 65116.75kB 10.10% | github.com/gohugoio/hugo/tpl/tplimpl.(*templateHandler).LookupLayout
65039.72kB 99.88% | github.com/gohugoio/hugo/tpl/tplimpl.(*templateHandler).findLayout
(pprof) list github.com/gohugoio/hugo/hugolib.\(\*pageState\).resolveTemplate
Total: 629.31MB
ROUTINE ======================== github.com/gohugoio/hugo/hugolib.(*pageState).resolveTemplate in /foo/src/github.com/gohugoio/hugo/worktrees/highlight-alloc/hugolib/page.go
0 61.90MB (flat, cum) 9.84% of Total
. . 488: if len(layouts) > 0 {
. . 489: d.Layout = layouts[0]
. . 490: d.LayoutOverride = true
. . 491: }
. . 492:
. 61.90MB 493: return p.s.Tmpl().LookupLayout(d, f)
. . 494:}
. . 495:
. . 496:// This is serialized
. . 497:func (p *pageState) initOutputFormat(isRenderingSite bool, idx int) error {
. . 498: if err := p.shiftToOutputFormat(isRenderingSite, idx); err != nil {