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

Remove defer for improved inlining in v1.20+ using PGO #218

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rajbarik
Copy link

@rajbarik rajbarik commented May 15, 2023

Go launched Profile-Guided Optimization (PGO) with v1.20.
With this, inlining optimization now uses a threshold called inlineHotMaxBudget which has a default value of 2000 for PGO-based inlining [Line 76, inl.go]. This will enable more inling. However, inlining continues not to work if a function/method contains defer statements [Line 619, inl.go]

This PR eliminates many defer constructs in scope.go and scope_registry.go in order to enable more inlining. For example, smaller functions such as scope::counter(sanitizedName string) and scope::gauge(name string) should be inlined after removing defers in them.

I should also mention that I have gone to the extreme in removing many defers. We should vet all the changes keeping in mind panic behaviors and make sure they are correct before merging this PR.

@CLAassistant
Copy link

CLAassistant commented May 15, 2023

CLA assistant check
All committers have signed the CLA.

@rajbarik
Copy link
Author

@prateek FYI.

@rabbbit
Copy link

rabbbit commented May 16, 2023

Did you measure the expected efficiency wins from this in any way? In other words, is the extra brittleness worth it?

I was hoping that https://go-review.googlesource.com/c/go/+/479095 would have fixed this - but it looks like they only change the closure behavior, not defer.

Is a similar change to allow inlinfing functions with defers not possible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants