]> git.maquefel.me Git - brevno-suite/hugo/commit
tpl: Add a partial lookup cache
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 10 Apr 2025 07:22:29 +0000 (09:22 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 10 Apr 2025 09:07:19 +0000 (11:07 +0200)
commit208a0de6c31354df6f9463d49e90db9dec935169
treed6886fd2f541f5c20e0af3b0736be7e7c3eb2900
parent18d2d2f98520b036a5138bc712a7e6843fa3380f
tpl: Add a partial lookup cache

````
                 │ stash.bench  │          perf-v146.bench           │
                 │    sec/op    │   sec/op     vs base               │
LookupPartial-10   248.00n ± 0%   14.75n ± 2%  -94.05% (p=0.002 n=6)

                 │ stash.bench │          perf-v146.bench          │
                 │    B/op     │   B/op     vs base                │
LookupPartial-10    48.00 ± 0%   0.00 ± 0%  -100.00% (p=0.002 n=6)

                 │ stash.bench │          perf-v146.bench           │
                 │  allocs/op  │ allocs/op   vs base                │
LookupPartial-10    3.000 ± 0%   0.000 ± 0%  -100.00% (p=0.002 n=6)
```

THe speedup above assumes reuse of the same partials over and over again, which I think is not uncommon.

This commits also adds some more lookup benchmarks. The current output of these on my MacBook looks decent:

```
BenchmarkLookupPagesLayout/Single_root-10                3031562               395.5 ns/op             0 B/op          0 allocs/op
BenchmarkLookupPagesLayout/Single_sub_folder-10          2515915               480.9 ns/op             0 B/op          0 allocs/op
BenchmarkLookupPartial-10                               84808112                14.13 ns/op            0 B/op          0 allocs/op
BenchmarkLookupShortcode/toplevelpage-10                 8111779               148.2 ns/op             0 B/op          0 allocs/op
BenchmarkLookupShortcode/nestedpage-10                   8088183               148.6 ns/op             0 B/op          0 allocs/op
```

Note that in the above the partial lookups are cahced, the others not (they are harder to cache because of the page path).

Closes #13571
common/maps/cache.go
hugolib/alias.go
hugolib/page.go
hugolib/page__common.go
hugolib/page__new.go
hugolib/page__per_output.go
hugolib/shortcode.go
resources/page/page.go
resources/page/pages_related.go
tpl/tplimpl/templatestore.go
tpl/tplimpl/templatestore_integration_test.go