-
Notifications
You must be signed in to change notification settings - Fork 4.2k
RuntimeHelpers.CreateSpan optimization for stackalloc #57123
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
RuntimeHelpers.CreateSpan optimization for stackalloc #57123
Conversation
972aacf to
0f2120d
Compare
83489e2 to
609cba8
Compare
609cba8 to
432d5e0
Compare
804a997 to
654aba8
Compare
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStackAllocInitializerTests.cs
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/CodeGen/EmitStackAllocInitializer.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/CodeGen/EmitStackAllocInitializer.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/CodeGen/EmitStackAllocInitializer.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/CodeGen/EmitStackAllocInitializer.cs
Outdated
Show resolved
Hide resolved
70dd5b4 to
de12627
Compare
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.
cool!
|
Thanks @svick! |
So this is not supposed to reach main? |
It is, at some point. As far as I can see, the required runtime code is ready (dotnet/runtime#60948 (comment)), so I think the next step would be to get answers to the questions I had above and then this could be probably merged into main. I don't know if I'm going to be able to do that soon. |
|
It's on the list of features we're trying to get into C# 11. This feature is mostly in the "just need to find some keyboard time" vs. "needs a lot of design". That is why we've pushed it further back in the schedule as we've prioritized items that need more design work. The schedule is very tight right now though as we had a number of last second asks that we're dealing with. |
This PR changes the IL generated for
stackallocin the following way:bytearrays directly from PE data; usinginitblkwhen all bytes are the same), there is no change.ReadOnlySpan<T>and all initializers are constant, the wholestackallocis replaced by a call toCreateSpan.Span<T>or when only some initializers are constant),CreateSpanis used as a part of regularstackalloccodegen, together withcpblk.The IL for array initializers is also changed:
bytewith all initializers constant is converted to ROS, the whole expression is replaced withCreateSpan.There are still some questions I have and things that would need addressing to make this code production quality:
GetPinnableReference(without any pinning) to get the backing data for the result ofCreateSpan, for use incpblk?LocalRewriter. Is there some way to do that?