-
-
Notifications
You must be signed in to change notification settings - Fork 661
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
Inline nullable basic types without allocations #11856
Comments
This is similar to #11332, but for nullables rather than parameter enums |
@basro Do you think this is something we could add to the inline constructor code somewhat easily? |
I don't have much knowledge of what goes on with null on static targets so I don't have any idea of what would need to change. @Simn could you get me a snapshot of the syntax tree before and after the inline constructor for a code sample that showcases the problem? I'd be able to reason about what is going on with that. |
Looking at this again, I wonder in which case this could even come up without being const-propagated away. If we statically know the null-ness and value of a local variable, then we likely end up optimizing it anyway. There could be artificial cases like this: function main() {
var a:Null<Int> = Math.random() > 0.5 ? 0 : 1;
if (a != null) {
trace(a);
}
} Here we don't know the value, but we do know the null-ness, which would allow us to optimize the branch away. However, this would require careful dataflow analysis in order to not break down immediately, e.g. on reassignment. On balance, I don't know if this is worth the effort. Do we have a real-life example of some code which suffers from this and isn't already optimized properly with |
At the moment
Null<Int>
andNull<Float>
used exclusively in one scope create unnecessary allocations on static platforms.The compiler could inline those away like it does for anonymous structures:
This is functionally the same as:
The text was updated successfully, but these errors were encountered: