OData / RESTier

A turn-key library for building RESTful services
http://odata.github.io/RESTier
Other
471 stars 137 forks source link

[2.0] Delay Query Materialization #614

Open mottibec opened 6 years ago

mottibec commented 6 years ago

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

robertmclaws commented 5 years ago

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 commented 5 years ago

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

andreav commented 2 years ago

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.