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

Support for OrderBy(..) in Async LINQ queries #44

Open
KrzysFR opened this issue Nov 26, 2014 · 2 comments
Open

Support for OrderBy(..) in Async LINQ queries #44

KrzysFR opened this issue Nov 26, 2014 · 2 comments
Labels
api Issues or changes related to the client API linq Async LINQ
Milestone

Comments

@KrzysFR
Copy link
Member

KrzysFR commented Nov 26, 2014

Currently, the Async LINQ queries to do not support the OrderBy(...) operator. You have to first call ToListAsync() and then sort the results in memory (using the regular LINQ-To-Object OrderBy(...).ToList().

The main issue with this operator, is that it must first buffer all the results in memory, before being able to sort them (the last one would be the first result once sorted). And then when the sorting is done, it will output all the results in burst. In effect, the first call to MoveNext() will take a very long time (99% of the query time), and then all successive MoveNext() calls will be instant and non-async (they will simply return the next item in an array).

As long as people use this as the last step in a query, with low item count, or with very selective Where(...) clauses in front, this should be OK.

Anyway, there does not seem to be any magical solution around this problem, and I hope that users of the API will think about what they do before doing something like tr.GetRange(subspaceWith10MillionKeys.ToRange()).OrderBy(kvp => ...).Take(10).ToListAsync() (which would need to read all 10 million keys, sort them all in memory, and then only take the first 10.

@KrzysFR KrzysFR added the api Issues or changes related to the client API label Nov 26, 2014
@KrzysFR KrzysFR added this to the 0.9.8 milestone Nov 26, 2014
@KrzysFR KrzysFR added the linq Async LINQ label Nov 26, 2014
@KrzysFR
Copy link
Member Author

KrzysFR commented Dec 2, 2014

First part of the work done in 713b793

@KrzysFR KrzysFR modified the milestones: 0.9.8, 0.9.9 Jan 26, 2015
@mohammadmaheer
Copy link

What about if I do have a list of objects and I want to use OrderBy(x=>x.SomeProperty)?
Here, I don't have benefit of async. Any thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Issues or changes related to the client API linq Async LINQ
Projects
None yet
Development

No branches or pull requests

2 participants