hugo icon indicating copy to clipboard operation
hugo copied to clipboard

Maybe cache the results of reflect.Type.MethodByName?

Open quasilyte opened this issue 3 years ago • 1 comments

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:

  1. Build hugo from sources
  2. Clone https://github.com/GSA/digitalgov.gov
  3. 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.

quasilyte avatar Jan 14 '22 22:01 quasilyte

Thanks for those numbers, I will have a look to see how to do it.

bep avatar Mar 08 '22 08:03 bep