Skip to content
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

Maybe cache the results of reflect.Type.MethodByName? #9386

Open
quasilyte opened this issue Jan 14, 2022 · 1 comment
Open

Maybe cache the results of reflect.Type.MethodByName? #9386

quasilyte opened this issue Jan 14, 2022 · 1 comment
Assignees
Milestone

Comments

@quasilyte
Copy link
Contributor

quasilyte commented Jan 14, 2022

See golang/go#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.

@bep bep self-assigned this Mar 8, 2022
@bep bep added this to the v0.94.0 milestone Mar 8, 2022
@bep
Copy link
Member

bep commented Mar 8, 2022

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

@bep bep modified the milestones: v0.94.0, v0.95.0, v0.96.0 Mar 9, 2022
@bep bep modified the milestones: v0.96.0, v0.97.0 Mar 24, 2022
@bep bep modified the milestones: v0.97.0, v0.98.0 Apr 13, 2022
@bep bep modified the milestones: v0.98.0, v0.99.0 Apr 28, 2022
@bep bep modified the milestones: v0.99.0, v0.100.0 May 24, 2022
@bep bep modified the milestones: v0.100.0, v0.101.0 May 31, 2022
@bep bep modified the milestones: v0.101.0, v0.102.0 Jun 16, 2022
@bep bep modified the milestones: v0.102.0, v0.103.0 Aug 28, 2022
@bep bep modified the milestones: v0.103.0, v0.104.0 Sep 15, 2022
@bep bep modified the milestones: v0.104.0, v0.105.0 Sep 23, 2022
@bep bep modified the milestones: v0.110.0, v0.111.0 Jan 26, 2023
@bep bep modified the milestones: v0.111.0, v0.112.0 Feb 15, 2023
@bep bep modified the milestones: v0.112.0, v0.113.0 Apr 15, 2023
@bep bep modified the milestones: v0.113.0, v0.115.0 Jun 13, 2023
@bep bep modified the milestones: v0.115.0, v0.116.0 Jun 30, 2023
@bep bep modified the milestones: v0.116.0, v0.117.0 Aug 1, 2023
@bep bep modified the milestones: v0.117.0, v0.118.0 Aug 30, 2023
@bep bep modified the milestones: v0.118.0, v0.119.0 Sep 15, 2023
@bep bep modified the milestones: v0.119.0, v0.120.0 Oct 5, 2023
@bep bep modified the milestones: v0.120.0, v0.121.0 Oct 31, 2023
@bep bep modified the milestones: v0.121.0, v0.122.0 Dec 6, 2023
@bep bep modified the milestones: v0.122.0, v0.123.0, v0.124.0 Jan 27, 2024
@bep bep modified the milestones: v0.124.0, v0.125.0 Mar 4, 2024
@bep bep modified the milestones: v0.125.0, Unscheduled Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants