RESTier icon indicating copy to clipboard operation
RESTier copied to clipboard

[2.0] Delay Query Materialization

Open mottibec opened this issue 7 years ago • 3 comments

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

mottibec avatar Sep 17 '18 17:09 mottibec

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 avatar Dec 17 '18 16:12 robertmclaws

https://github.com/OData/RESTier/blob/45f858d8cb62f0c0d854b5cfdca61601f4cea409/src/Microsoft.Restier.AspNet/RestierController.cs#L587-L589

robertmclaws avatar Jun 11 '19 17:06 robertmclaws

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.

andreav avatar Oct 12 '21 14:10 andreav