tally
tally copied to clipboard
Remove defer for improved inlining in v1.20+ using PGO
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.
@prateek FYI.
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?