Rework template handling for function and map lookups
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 10 Dec 2019 18:56:44 +0000 (19:56 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 12 Dec 2019 09:04:35 +0000 (10:04 +0100)
commita03c631c420a03f9d90699abdf9be7e4fca0ff61
treefcc245c75aa6cc6dc5be40a614700b6aca26c84f
parent167c01530bb295c8b8d35921eb27ffa5bee76dfe
Rework template handling for function and map lookups

This is a big commit, but it deletes lots of code and simplifies a lot.

* Resolving the template funcs at execution time means we don't have to create template clones per site
* Having a custom map resolver means that we can remove the AST lower case transformation for the special lower case Params map

Not only is the above easier to reason about, it's also faster, especially if you have more than one language, as in the benchmark below:

```
name                          old time/op    new time/op    delta
SiteNew/Deep_content_tree-16    53.7ms ± 0%    48.1ms ± 2%  -10.38%  (p=0.029 n=4+4)

name                          old alloc/op   new alloc/op   delta
SiteNew/Deep_content_tree-16    41.0MB ± 0%    36.8MB ± 0%  -10.26%  (p=0.029 n=4+4)

name                          old allocs/op  new allocs/op  delta
SiteNew/Deep_content_tree-16      481k ± 0%      410k ± 0%  -14.66%  (p=0.029 n=4+4)
```

This should be even better if you also have lots of templates.

Closes #6594
41 files changed:
commands/server.go
create/content_template_handler.go
deps/deps.go
hugolib/alias.go
hugolib/case_insensitive_test.go
hugolib/embedded_shortcodes_test.go
hugolib/hugo_modules_test.go
hugolib/hugo_sites.go
hugolib/hugo_smoke_test.go
hugolib/page.go
hugolib/page__per_output.go
hugolib/page_test.go
hugolib/shortcode.go
hugolib/shortcode_test.go
hugolib/site.go
hugolib/sitemap_test.go
hugolib/template_engines_test.go [deleted file]
hugolib/testhelpers_test.go
langs/language.go
resources/resource_transformers/templates/execute_as_template.go
scripts/fork_go_templates/main.go
tpl/collections/apply.go
tpl/collections/apply_test.go
tpl/internal/go_templates/texttemplate/exec.go
tpl/internal/go_templates/texttemplate/hugo_exec.go [deleted file]
tpl/internal/go_templates/texttemplate/hugo_template.go
tpl/internal/go_templates/texttemplate/hugo_template_test.go [new file with mode: 0644]
tpl/partials/partials.go
tpl/resources/resources.go
tpl/template.go
tpl/tplimpl/embedded/templates.autogen.go
tpl/tplimpl/embedded/templates/alias.html [new file with mode: 0644]
tpl/tplimpl/shortcodes.go
tpl/tplimpl/template.go
tpl/tplimpl/templateFuncster.go
tpl/tplimpl/templateProvider.go
tpl/tplimpl/template_ast_transformers.go
tpl/tplimpl/template_ast_transformers_test.go
tpl/tplimpl/template_funcs.go
tpl/tplimpl/template_funcs_test.go
tpl/tplimpl/template_info_test.go