Question

I have a WebAPI2/OData Breeze server (.NET 4.5, EntityFramework 6) that I'm querying from a Breeze/AngularJS client. I expected running a full entity query to be slower than running a projection, but I expected it to be somewhat proportional to the amount of data crossing the wire. But if I run a projection like:

var query = breeze.EntityQuery.from('Users')
    .where('firstName', 'startsWith', 'K')
    .select('firstName');

return manager
    .executeQuery(query)
    .then(querySucceeded, _queryFailed);

I get 45KB of data, and the request takes 15ms. (Release mode)

And I run a full entity query like:

var query = breeze.EntityQuery.from('Users')
    .where('firstName', 'startsWith', 'K');

return manager
    .executeQuery(query)
    .then(querySucceeded, _queryFailed);

I get 159KB of data, and the request takes 154ms. (Release mode)

That makes the entity query return about 3x the data, but it takes 10x longer. The discrepancy is even more apparent if I run in Debug mode. Then the projection takes 39ms, but the full entity query takes a full 8120ms(!), which makes debugging a bit of a pain. So in Debug mode the full entity query actually takes over 200x longer than the projection.

Why would a full entity query take disproportionately longer, and in Debug mode in particular? Is this normal, or is this indicative of some issue?

Was it helpful?

Solution

Projection queries can be much faster than 'entity' queries in Breeze because, in general, there is no need to merge the result of a projection into the EntityManager cache, which is a time consuming process if you have a lot of entities. ( Some caveat's here if the projection itself contains entities).

If you do not need this capability or only want it some of the time Breeze has a 'noTracking' method that you can call on the query. (see: the 'noTracking' section on this page: http://www.breezejs.com/documentation/querying-depth ). No tracking queries, especially those involving a lot of entities will be MUCH faster.

In terms of Debug vs Release performance, this is presumably purely a 'server side' issue and in my experience is largely a Visual Studio artifact.

Note that if most of your work is just client side javascript can have your server run in a separate solution in 'Release' mode, and just start it up once and leave it running. Iterating during the development of the client side is then much faster.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top