tl;dr: hugo happens to call MethodByName a lot for types with many exported methods (120).
It could be beneficial to cache the MethodByName results to avoid this pathological performance regression. Using the binary search makes big sites (https://github.com/GSA/digitalgov.gov in this case) build ~20% faster, but there is a chance that this optimization is not worthwhile in the Go stdlib itself.
With caching, it should be possible to reduce the overhead and get the speedup that is comparable to that.
Since I don't know hugo code at all, it's hard for me to give any other suggestions.
See https://github.com/golang/go/issues/50617
tl;dr: hugo happens to call MethodByName a lot for types with many exported methods (120).
It could be beneficial to cache the MethodByName results to avoid this pathological performance regression. Using the binary search makes big sites (https://github.com/GSA/digitalgov.gov in this case) build ~20% faster, but there is a chance that this optimization is not worthwhile in the Go stdlib itself.
With caching, it should be possible to reduce the overhead and get the speedup that is comparable to that.
Since I don't know hugo code at all, it's hard for me to give any other suggestions.
How to reproduce the behavior:
hugo
in the cloned repo root (with CPU profiling enabled)Note that there will be a few warnings related to the usages of
getenv()
, but they can be fixed rather easily.