mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-21 21:35:28 +02:00
Only create LazyContentProvider for the non-rendering Site
Which saves a fair amound of allocations: ``` gobench --package ./hugolib --bench "SiteNew/Regular_D" --base master ``` Before: ``` name old time/op new time/op delta SiteNew/Regular_Deep_content_tree-10 40.7ms ± 3% 41.2ms ± 1% ~ (p=0.343 n=4+4) name old alloc/op new alloc/op delta SiteNew/Regular_Deep_content_tree-10 27.7MB ± 0% 28.8MB ± 0% +3.76% (p=0.029 n=4+4) name old allocs/op new allocs/op delta SiteNew/Regular_Deep_content_tree-10 304k ± 0% 329k ± 0% +8.07% (p=0.029 n=4+4) ``` After: ``` name old time/op new time/op delta SiteNew/Regular_Deep_content_tree-10 34.2ms ± 1% 34.7ms ± 1% ~ (p=0.114 n=4+4) name old alloc/op new alloc/op delta SiteNew/Regular_Deep_content_tree-10 27.7MB ± 0% 28.1MB ± 0% +1.38% (p=0.029 n=4+4) name old allocs/op new allocs/op delta SiteNew/Regular_Deep_content_tree-10 304k ± 0% 314k ± 0% +3.03% (p=0.029 n=4+4) ``` Updates #8919
This commit is contained in:
@@ -49,6 +49,10 @@ func NewLazyContentProvider(f func() (ContentProvider, error)) *LazyContentProvi
|
||||
return &lcp
|
||||
}
|
||||
|
||||
func (lcp *LazyContentProvider) Reset() {
|
||||
lcp.init.Reset()
|
||||
}
|
||||
|
||||
func (lcp *LazyContentProvider) Content() (interface{}, error) {
|
||||
lcp.init.Do()
|
||||
return lcp.cp.Content()
|
||||
@@ -67,35 +71,29 @@ func (lcp *LazyContentProvider) PlainWords() []string {
|
||||
func (lcp *LazyContentProvider) Summary() template.HTML {
|
||||
lcp.init.Do()
|
||||
return lcp.cp.Summary()
|
||||
|
||||
}
|
||||
|
||||
func (lcp *LazyContentProvider) Truncated() bool {
|
||||
lcp.init.Do()
|
||||
return lcp.cp.Truncated()
|
||||
|
||||
}
|
||||
|
||||
func (lcp *LazyContentProvider) FuzzyWordCount() int {
|
||||
lcp.init.Do()
|
||||
return lcp.cp.FuzzyWordCount()
|
||||
|
||||
}
|
||||
|
||||
func (lcp *LazyContentProvider) WordCount() int {
|
||||
lcp.init.Do()
|
||||
return lcp.cp.WordCount()
|
||||
|
||||
}
|
||||
|
||||
func (lcp *LazyContentProvider) ReadingTime() int {
|
||||
lcp.init.Do()
|
||||
return lcp.cp.ReadingTime()
|
||||
|
||||
}
|
||||
|
||||
func (lcp *LazyContentProvider) Len() int {
|
||||
lcp.init.Do()
|
||||
return lcp.cp.Len()
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user