Conversation
| .AsOrdered() | ||
| .Select(i => ComputeProvenanceResult(itemToMatch, i)) | ||
| .Select((item, index) => ComputeProvenanceResult(itemToMatch, item, index)) | ||
| .AsSequential() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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