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
Array -> Memory -> Span overly defensive? #10836
Comments
Issue with struct tearing on |
Right. |
I think the JIT will automatically elide the null check in the |
@GrabYourPitchforks this is fixed now? |
Yes, it no longer uses the regular (checked) span ctor: Fixed in dotnet/coreclr#20386 |
Creating a {ReadOnly}Memory from an array does lots of checks; which is correct
https://github.com/dotnet/coreclr/blob/9d1e7dd8eb744b14eb4a90b401e854d7a5f79fff/src/System.Private.CoreLib/shared/System/Memory.cs#L96-L113
Slicing a {ReadOnly}Memory also performs bounds checks based on the confirmed offset and lengths
However creating a Span from and array backed {ReadOnly}Memory uses the regular array constructor
https://github.com/dotnet/coreclr/blob/9d1e7dd8eb744b14eb4a90b401e854d7a5f79fff/src/System.Private.CoreLib/shared/System/Memory.cs#L286-L289
Which then rechecks all the parameters again
https://github.com/dotnet/coreclr/blob/9d1e7dd8eb744b14eb4a90b401e854d7a5f79fff/src/System.Private.CoreLib/shared/System/Span.Fast.cs#L73-L89
This makes an array backed Memory the most expensive kind of Span creator.
Does it need to recheck everything or can it use an internal Span .ctor that bypasses the additional checks?
/cc @jkotas @stephentoub @GrabYourPitchforks @davidfowl @ahsonkhan
The text was updated successfully, but these errors were encountered: