New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get rid of redundant viper.Get* calls #2728
Comments
Curious. This is the HasMenuCurrent, I guess. I will get rid of that one right away. This is useful. |
That said, if you look past the sectionPagesMenu setting, which I would say is a bug, the others are also low in the big picture. It isn't a map lookup, but still fairly cheap -- but it adds up I guess. We should find a clean way to fix this. This is possible related to the "global refactor" issue. |
Yes, I agree with you, it's cheap, but could be better :) |
How about a middle layer between hugo and viper like a part of "global refactor"? It will be a separate package and could be named like package global
import (
... dependencies
)
var (
absContentDir string
baseURL string
canonifyURLs bool
currentLang hugolib.Language // with this property `helpers.Config` could be removed
templateBaseURL template.URL
uglyURLs bool
... other values
)
func AbsContentDir() string {
if absContentDir == "" {
absContentDir = helpers.AbsPathify(viper.GetString("contentDir"))
}
return absContentDir
}
... and so on And if developer needs some config data, he/she should use either this package for global values or This can improve performance, because of decreasing of viper accesses and |
It shouldn't be a global, but what you talk about kind of exist already, see So your idea is very good, but the implementation has room for improvement: We don't want more globals in Hugo, and this should not be lazily initialized ( We may put the
|
Oh, I didn't see |
PathSpec was pretty recently added. |
But to implement this, one should improve |
The TODOS are mostly about getting rid of all the globals, which is a bigger job (and a separate issue). The current |
|
The problem is, what some global variables (like |
Update:
examples/multilingual
docs
version of hugo: dev 2ea242d |
This is very useful. We should do more, but I'd welcomed a PR for Hugo 0.19 that fixes |
I will try to work in this direction |
@bep, I just want to know your opinion about adding method // BaseURL just returns the baseURL value.
func (p *PathSpec) BaseURL() string {
return p.baseURL
}
|
Enforce usage of PathSpec Fixes gohugoio#3060 Updates gohugoio#2728
Building https://github.com/rdwatters/hugo-docs-concept:
|
This is fixed now. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I was just interested, how often hugo calls
viper.Get*
with specific keys. The results are:examples/blog
examples/multilingual
docs
version of hugo: dev dbb0c1c
I think, what the most of these accesses are redundant and could be removed, so the performance will be better. And the repeating
helpers.AbsPathify
calls should also be considered.The text was updated successfully, but these errors were encountered: