Skip to content
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

Use Roslyn support for RuntimeHelpers.CreateSpan #70179

Closed
wants to merge 1 commit into from

Conversation

stephentoub
Copy link
Member

As of dotnet/roslyn#61414, the optimization that previously extended only to byte/sbyte/bool will now also support char/ushort/short/uint/int/ulong/long/float/double. This PR uses it throughout dotnet/runtime. However, because of endianness issues, this requires the RuntimeHelpers.CreateSpan method that only exists as of .NET 7, so trying to use this optimization in builds targeting < .NET 7 will be a significant deoptimization. Until we have dedicated syntax (ala dotnet/csharplang#5295) and/or an analyzer (#69577) to avoid such issues, we need to be very careful where this applied.

I'm putting this up as a draft now for feedback, but we must not merge this until we've picked up a Roslyn compiler that has the aforementioned improvement.

Closes #60948
cc: @VSadov, @jcouv, @davidwrighton, @GrabYourPitchforks

@stephentoub stephentoub added NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) tenet-performance Performance related issue labels Jun 2, 2022
@stephentoub stephentoub added this to the 7.0.0 milestone Jun 2, 2022
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost assigned stephentoub Jun 2, 2022
@stephentoub stephentoub force-pushed the usecreatespan branch 3 times, most recently from dee4484 to 196281d Compare June 3, 2022 01:04
@huoyaoyuan
Copy link
Member

huoyaoyuan commented Jun 3, 2022

Current implementation throws hardly for big endian. It still allows the option to copy the field and reverse the endianness in memory, right? Just make sure this feature is not impossible or extremely inefficient to implement for big endian.

@stephentoub
Copy link
Member Author

stephentoub commented Jun 3, 2022

Current implementation throws hardly for big endian. It still allows the option to copy the field and reverse the endianness in memory, right? Just make sure this feature is not impossible or extremely inefficient to implement for big endian.

The purpose of the CreateSpan API is to address endianness. coreclr doesn't support big endian at all today (well beyond this particular method), but mono does, including with this method.

#if G_BYTE_ORDER != G_LITTLE_ENDIAN

@ghost
Copy link

ghost commented Jun 3, 2022

Tagging subscribers to this area: @dotnet/area-meta
See info in area-owners.md if you want to be subscribed.

Issue Details

As of dotnet/roslyn#61414, the optimization that previously extended only to byte/sbyte/bool will now also support char/ushort/short/uint/int/ulong/long/float/double. This PR uses it throughout dotnet/runtime. However, because of endianness issues, this requires the RuntimeHelpers.CreateSpan method that only exists as of .NET 7, so trying to use this optimization in builds targeting < .NET 7 will be a significant deoptimization. Until we have dedicated syntax (ala dotnet/csharplang#5295) and/or an analyzer (#69577) to avoid such issues, we need to be very careful where this applied.

I'm putting this up as a draft now for feedback, but we must not merge this until we've picked up a Roslyn compiler that has the aforementioned improvement.

Closes #60948
cc: @VSadov, @jcouv, @davidwrighton, @GrabYourPitchforks

Author: stephentoub
Assignees: stephentoub
Labels:

NO-MERGE, area-Meta, tenet-performance

Milestone: 7.0.0

@stephentoub stephentoub force-pushed the usecreatespan branch 2 times, most recently from 3248a47 to 06c0d49 Compare June 13, 2022 13:52
@@ -5455,12 +5453,14 @@ internal bool MatchSpecifiedWords(string target, bool checkWordBoundary, ref int
// Check word by word
int targetPosition = 0; // Where we are in the target string
int thisPosition = Index; // Where we are in this string
int wsIndex = target.IndexOfAny(WhiteSpaceChecks, targetPosition);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if there is analyzer for such patterns

The optimization that previously extended only to byte/sbyte/bool now also supports char/ushort/short/uint/int/ulong/long/float/double.
@stephentoub
Copy link
Member Author

It looks like the compiler dependency won't land in time for the compiler change to be merged. Closing for .NET 7.

@ghost ghost locked as resolved and limited conversation to collaborators Aug 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Meta NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) tenet-performance Performance related issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[API Proposal]: ReadOnlySpan<T> CreateSpan<T>(RuntimeFieldHandle)
5 participants