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

[2.0] Delay Query Materialization #614

Open
mottibec opened this issue Sep 17, 2018 · 3 comments
Open

[2.0] Delay Query Materialization #614

mottibec opened this issue Sep 17, 2018 · 3 comments
Labels
P1 perf Potential performance improvements
Milestone

Comments

@mottibec
Copy link

in DefaultQueryExecutor.ExecuteQueryAsync there's a call to query.ToList() that loads all results into memory

@robertmclaws robertmclaws added the perf Potential performance improvements label Dec 17, 2018
@robertmclaws robertmclaws changed the title return query results into stream without loading into memory Optimize QueryExecutor results to delay materialization Dec 17, 2018
@robertmclaws
Copy link
Collaborator

So, it appears that all QueryExecutors will execute their queries in-memory at some point during the process. This is a relatively standard pattern, even in WebAPI proper (return query.ToList() happens all the time).

So the question becomes, it is possible to delay materialization of the query until it is later in the pipeline. .NET Core has done so much work to optimize for performance, I'll have to see what we can do.

@robertmclaws robertmclaws added P1 and removed P3 labels Jun 11, 2019
@robertmclaws
Copy link
Collaborator

var queryResult = await Api.QueryAsync(queryRequest, cancellationToken).ConfigureAwait(false);
var result = queryResult.Results.AsQueryable();
return result;

@robertmclaws robertmclaws added this to the 2.0 milestone Oct 6, 2019
@andreav
Copy link

andreav commented Oct 12, 2021

Hello,
I think also this line materializes results unnecessarily:

https://github.dev/OData/RESTier/blob/38b8de60c0e7169f31e88872bc4e1313f754080a/src/Microsoft.Restier.EntityFramework.Shared/Query/EFQueryExecutor.cs#L69-L69

I tried changing from:

return new QueryResult(await query.ToArrayAsync(cancellationToken).ConfigureAwait(false));

to

return new QueryResult(query);

and there is no more loading of the whole query result in memory.

@robertmclaws robertmclaws changed the title Optimize QueryExecutor results to delay materialization [2.0] Delay Query Materialization Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 perf Potential performance improvements
Projects
Status: No status
Development

No branches or pull requests

3 participants