tally icon indicating copy to clipboard operation
tally copied to clipboard

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

Open rajbarik opened this issue 2 years ago • 3 comments

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.

rajbarik avatar May 15 '23 20:05 rajbarik

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar May 15 '23 20:05 CLAassistant

@prateek FYI.

rajbarik avatar May 16 '23 04:05 rajbarik

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?

rabbbit avatar May 16 '23 16:05 rabbbit