hugo
hugo copied to clipboard
Maybe cache the results of reflect.Type.MethodByName?
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:
- Build hugo from sources
- Clone https://github.com/GSA/digitalgov.gov
- Run
hugo
in the cloned repo root (with CPU profiling enabled)
git clone https://github.com/GSA/digitalgov.gov.git
cd digitalgov.gov
hugo --profile-cpu cpu.out
Note that there will be a few warnings related to the usages of getenv()
, but they can be fixed rather easily.
Thanks for those numbers, I will have a look to see how to do it.