Skip to content

AsOrdered was removed#8092

Merged
rokonec merged 2 commits intomainfrom
dev/mipavlik/vs-ui-delay
Nov 4, 2022
Merged

AsOrdered was removed#8092
rokonec merged 2 commits intomainfrom
dev/mipavlik/vs-ui-delay

Conversation

@MichalPavlik
Copy link
Copy Markdown
Member

@MichalPavlik MichalPavlik commented Oct 26, 2022

Fixes AB#1618509

Context

AsOrdered causes UI delays in VS due to thread blocking.

Changes Made

Processing items is still parallel, but sorting is now done classically based on original item index.

Testing

Existing unit tests are passing

.AsOrdered()
.Select(i => ComputeProvenanceResult(itemToMatch, i))
.Select((item, index) => ComputeProvenanceResult(itemToMatch, item, index))
.AsSequential()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I am not familar with AsSequential (I don't think I used it in my standalone prototypes), but we should make sure its implementation doesn't use the same MergeSortCooperatively that was causing the problem.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wasn't either! My impression from the docs was that it was basically just "give me an IEnumerable out of this parallel thing" so it's WhenAll, and shouldn't have any blocking. But if it's not necessary I'd also prefer to remove it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

AsSequential unwraps the underlying IEnumerable (effectively undoing AsParallel) to make sure that the OrderBy doesn't use the problematic parallel implementation. As such it cannot be removed if we want to keep the whole thing in one query.

The prototype had a list of tuples as its final product, i.e. it's missing the sorting which is required to make List<ProvenanceResult>.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

First of all, thanks @adrianvmsft for detailed analysis you did for this issue. As my colleagues noted, AsSequential switches from PLINQ (ParallelQuery) to standard enumerable. I wanted to avoid sorting in parallel way. The question is, if the sorted collection has some benefit. Tests are passing after removing OrderBy, but maybe there are some perf implications in further processing of this collection.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thank you!
I tried a similar query (using AsSequential) in a standalone app, and I can confirm that it does not hit the MergeSortCooperatively function.

@Forgind Forgind added the merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now. label Nov 2, 2022
@rokonec rokonec merged commit dd0d79b into main Nov 4, 2022
@rokonec rokonec deleted the dev/mipavlik/vs-ui-delay branch November 4, 2022 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants