-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
.NET 10 Preview 3 - Runtime #9823
Conversation
@amanasifkhalid are you planning on adding the codegen notes? |
@AndyAyersMS yes, I'll have something up shortly... |
|
||
For more information on stack allocation improvements in the JIT compiler, check out [dotnet/runtime #108913](https://github.com/dotnet/runtime/issues/108913). | ||
|
||
## Improved Code Layout |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AndyAyersMS I'm not sure how we want to highlight this work externally. Right now, it reads pretty bookish, though I'm not sure if there's a way around that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to keep this at a higher level we could create a benchmark with similar pattern and use the [MemoryDiagnoser]
to show there is now less allocation.
Though it might also run a bit slower since we're now paying to zero init the array in the method rather than getting zeroed memory "for free" from the heap. Structuring the benchmark so it properly reflects when this cost is paid on .NET 9 might be tricky.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I meant the 3-opt writeup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the 3-opt writeup is ok.
} | ||
``` | ||
|
||
The lifetime of `words` is scoped to the `Print` method, and the JIT can avoid heap-allocating the strings `"Hello"` and `"world!"` already. However, the fact that `words` is an array of `strings`, a reference type, would previously stop the JIT from stack-allocating it. Now, the JIT can eliminate every heap allocation in the above example. At the assembly level, the code for `Print` used to look like this: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the strings are actually heap allocated here, but that happens when the method is JITed, and their addresses are stable and can be incorporated into the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
|
||
For more information on stack allocation improvements in the JIT compiler, check out [dotnet/runtime #108913](https://github.com/dotnet/runtime/issues/108913). | ||
|
||
## Improved Code Layout |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to keep this at a higher level we could create a benchmark with similar pattern and use the [MemoryDiagnoser]
to show there is now less allocation.
Though it might also run a bit slower since we're now paying to zero init the array in the method rather than getting zeroed memory "for free" from the heap. Structuring the benchmark so it properly reflects when this cost is paid on .NET 9 might be tricky.
Please ping me when ready to merge |
@jamesmontemagno I don't have anything else to add |
@AndyAyersMS anything else? |
No description provided.