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

Optimized struct enumerators #3341

Conversation

Sergio0694
Copy link
Member

@Sergio0694 Sergio0694 commented Jun 11, 2020

Follow up for #3128 and #3273

PR Type

What kind of change does this PR introduce?

  • Optimization

@michael-hawker NOTE: this PR has no functional changes, I literally just shuffled some code around and removed some unnecessary types (as I've moved the code to the parent types). All the existing methods and operations are exactly the same as before, I didn't change anything at all there.

What is the current behavior?

The Span<T>/T[]/T[,] enumerators use a secondary enumerator type to perform the actual enumeration. This causes an unnecessary initial copy of the captured values, and introduces a second generic type with a couple method that the JIT compiler has to compile to native code (for value types).

What is the new behavior?

The GetEnumerator() now simply returns this, so the second type is no longer needed. All the enumeration methods are added directly to the first type. The enumerator types are no longer marked as readonly to allow direct enumeration on them. This is not a problem since those were always supposed to be used once anyway and never store anywhere (as they're ref struct types).

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tested code with current supported SDKs
  • Pull Request has been submitted to the documentation repository instructions. Link:
  • Sample in sample app has been added / updated (for bug fixes / features)
  • Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Header has been added to all new source files (run build/UpdateHeaders.bat)
  • Contains NO breaking changes

@ghost
Copy link

ghost commented Jun 11, 2020

Thanks Sergio0694 for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌

@ghost ghost assigned michael-hawker Jun 11, 2020
- The one for rows is not needed from .NET Core 2.1 and above
- The other has the extra ToArray API which needs the initial values to remain available, and the type to be readonly
@michael-hawker
Copy link
Member

Thanks @Sergio0694, I'm still inclined to move this to 7.0 since we're trying to close down 6.1 still...

@azchohfi thoughts? This still seems pretty straight-forward and should have test coverage (which pass).

@azchohfi
Copy link
Contributor

Yeah, I'm not worried.

Copy link
Contributor

@vgromfeld vgromfeld left a comment

Choose a reason for hiding this comment

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

:shipit:

@michael-hawker michael-hawker added this to the 6.1 milestone Jun 12, 2020
@michael-hawker michael-hawker merged commit 4aca259 into CommunityToolkit:master Jun 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants