-
Notifications
You must be signed in to change notification settings - Fork 909
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
compiler: mark the source argument to the append builtin as not escaping #4576
Conversation
|
ed2a14e
to
ab62410
Compare
ab62410
to
7f864f4
Compare
7f864f4
to
8691402
Compare
This looks cool. I wonder how many times this optimization actually triggers? |
Good question. This change is not enough for the strconv.Append* functions to allow stack allocating the destination argument. For that, I probably need an argument-escapes-to-return-value attribute/pass like big Go does. Do you have any ideas how to approach that in TinyGo? |
I think @aykevl had some ideas on being able to rely more on llvm for escape analysis but I don't know the status of that work. |
I can't seem to get this to trigger.
|
8691402
to
3dc446d
Compare
I taught the escape pass about LLVM's extractvalue instruction, and your program now triggers the optimization. |
I added some logging and ran this across the test corpus. This triggered way less frequently than I was expecting. Logging patch:
Outputs:
And from 2024/11/01 21:25:15 sliceAppend heap->stack: /Users/dgryski/go/src/go.googlesource.com/go/src/strconv/atoi_test.go:657 -> doesn't escape triggered :0
|
Indeed, without inter-procedural analysis this optimization only works within functions. I'm tempted to look into porting big Go's escape analysis pass (https://github.com/golang/go/tree/master/src/cmd/compile/internal/escape), most importantly to avoid surprises where TinyGo heap allocates while big Go doesn't. Do you see any fundamental problems in that approach? |
Filed in #4579. Closing this for now. |
No description provided.