-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
fmt: Printf arguments escape to heap #19720
Comments
I'm not familiar with the compiler and the |
This is #8618 I believe. |
This is not related to interface. Following code doesn't make the input arguments escape.
|
@mvdan, I use log package quite often. The log package warps the fmt functions. So I hope the fix is good to optimize log functions. But if there are many different strings needed to be passed to the fmt.Print functions in a goroutine, maybe it is not bad to allocate them on heap, to avoid stack growing and shinking. |
I'm just surprised to see that the performance of |
I'll keep this open as a long-term meta bug about escape analysis, but small examples are generally more actionable. |
Analyzing
The only way I see to fix this is to have type-dependent escape analysis. I don't see that happening any time soon. |
|
yes, sometimes, it is. Another bad side effect is these functions change what it measure when it participate. |
yes, sometimes, it is. Another bad side effect is these functions change what they measure when they participate. |
Is it easier to write something like //go:escapesArgToHeap , then put it before the function body? |
Yes, I confirm duplicate of #8618. |
It looks it is caused by the pp struct in print.go which holds the printed arguments and pp values are referenced by other heap values. This can be avoided.
The text was updated successfully, but these errors were encountered: