-
Notifications
You must be signed in to change notification settings - Fork 919
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: ensure iterators are inlined in -opt=z #4512
Comments
Probably we'll need to figure out exactly which optimization pass(es) are responsible for this particular optimization and hope that turning just those ones on is sufficient to make this "always work". |
While I agree it would be great to fix this, in general you can't really rely on the compiler optimizing anything (including heap allocs). Also note that |
I did some more investigation and it looks like everything is inlined as expected (even at I think the right way to fix this is by using the heap-to-stack transform that's part of the LLVM Attributor pass. Unfortunately that pass doesn't know that pointers returned by our |
Wrote a patch: llvm/llvm-project#113299 |
"Performance" is actually not even that important for me. The deal breaker for my uses is the tendency of (typically small) frequent allocations to fragment the heap so much that out-of-memory panics occur when a larger allocation arrives. My current strategy is to eliminate allocations for frequently run code (GUI refreshes) which both avoids fragmentation and is faster. A longer term strategy is to not fragment the heap so much, but as you wrote somewhere a moving collector is difficult and won't help performance. Thank you for the LLVM patch. Do I have to do anything special on the TinyGo side to try it out, other than patching LLVM and adding the "nofree" attribute? Also, is the comment "for your own purpose, you can disable/filter out H2S AA explicitly when you construct the attributor" relevant to achieve better H2S in TinyGo? |
Yes. I have not tested this patch with TinyGo yet, some more LLVM work might be needed (I just don't know).
I actually don't know what that comment really means, or what it is referring to. I've asked for clarification. |
Can anything be done on our side while we wait for a LLVM solution? For example, will marking every pointer argument to every function "nofree" make the H2S pass effective? |
The idiom for iterator constructors is to return a closure that captures the iterator arguments, if any. It's crucial for the performance of range-over-func that the constructor doesn't incur allocations. Therefore, it seems to me functions that (nearly) immediately return a closure should always be inlined, regardless of optimization level. Or, at the very least, any function that returns a function that can be ranged over.
The text was updated successfully, but these errors were encountered: