Skip to content

Conversation

@Sergio0694
Copy link
Member

Fixes #3947

PR Type

What kind of change does this PR introduce?

  • Bugfix

What is the current behavior?

[ReadOnly]Span2D<T>.TryGetSpan throws an exception when wrapping a T[] instance on legacy frameworks.

What is the new behavior?

[ReadOnly]Span2D<T>.TryGetSpan works correctly on legacy frameworks.

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)
  • New major technical changes in the toolkit have or will be added to the Wiki e.g. build changes, source generators, testing infrastructure, sample creation changes, etc...
  • 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

@Sergio0694 Sergio0694 added the high-performance 🚂 Issues/PRs for the Microsoft.Toolkit.HighPerformance package label Apr 19, 2021
@ghost
Copy link

ghost commented Apr 19, 2021

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 requested review from Kyaa-dost, Rosuavio, azchohfi and michael-hawker April 19, 2021 21:29
@ghost ghost added the bug 🐛 An unexpected issue that highlights incorrect behavior label Apr 19, 2021
@Sergio0694 Sergio0694 force-pushed the bugfix/span2d-trygetspan branch 2 times, most recently from 1e0f390 to 3ac46c2 Compare April 21, 2021 12:52
@michael-hawker
Copy link
Member

@Sergio0694 was the original code done for a performance thing, does that impact that?

@Sergio0694
Copy link
Member Author

@michael-hawker Not sure I understand the question, could you clarify what you mean? Do you mean why do we have the TryGetSpan API at all, or why the line I changed was written that way instead of some other way (if so, how?), or something else?

As for the performance difference of this PR in general though, the new version with the fix is comparatively just as fast as the other one (note that that IndexOf method I'm calling is still O(1), it just calculates the index by calculating the pointer offset delta and dividing by element size, it's not actually enumerating anything), plus this isn't really a hot path anyway 😄

In particular, that IndexOf method being called is this extension below (not the IndexOf from LINQ or anything like that):

https://github.com/windows-toolkit/WindowsCommunityToolkit/blob/c31e049bc6b3120364abf1d8a6f3967e6e9eb927/Microsoft.Toolkit.HighPerformance/Extensions/SpanExtensions.cs#L161-L174

Does that help? 🙂

Copy link
Member

@michael-hawker michael-hawker left a comment

Choose a reason for hiding this comment

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

Yeah, was just asking about the change in syntax and if it had an impact one the generation/code execution time, as I wasn't sure if the original code was optimized for that or not. So if it's all the same and you've done the analysis, that's all I wanted to know. 🙂 (I assumed you had, as always, but do like to check sometimes... 😋)

@ghost
Copy link

ghost commented Apr 23, 2021

Hello @michael-hawker!

Because this pull request has the auto merge :zap: label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@Sergio0694 Sergio0694 force-pushed the bugfix/span2d-trygetspan branch from 3ec1a2c to e2c2580 Compare April 24, 2021 11:40
@ghost ghost merged commit 7e2d8a8 into CommunityToolkit:master Apr 24, 2021
@Sergio0694 Sergio0694 deleted the bugfix/span2d-trygetspan branch April 24, 2021 13:10
@michael-hawker michael-hawker added this to the 7.0.2 milestone May 11, 2021
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto merge ⚡ bug 🐛 An unexpected issue that highlights incorrect behavior high-performance 🚂 Issues/PRs for the Microsoft.Toolkit.HighPerformance package hotfix 🌶

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Span2D/ReadOnlySpan2D.TryGetSpan() has incorrect implementation for legacy framework

3 participants