Asynchronous data loading in Entity-Framework? - entity-framework

Did anyone hear about asynchronous executing of an EF query?
I want my items control to be filled right when the form loads and the user should be able to view the list while the rest of the items are still being loaded.
Maybe by auto-splitting the execution in bulks of items (i.e. few queries for each execution) all in same connection.
I posted a feature suggestion to Microsoft, please share them with your ideas as well.

Not wanting to sound like a commercial, but I noticed that the latest DevExpress grid gives features like this in their WPF grid. Essentially you want to load visible-count items first, then load the rest in a background thread so your UI isn't freezing up. The background thread should probably load another page at a time and make them available to the UI thread.
It's something you would want to think about carefully and make sure you get it right, or simply buy a control that does the hard work for you.

I take from your link that this is a web app. Is that correct?
A Query must complete and return data before rendering can begin. An EF feature will not help you here. Rather. look at breaking up your process into several processes that can be done at once.
Keep in mind that ASP.NET cannot return a response to a browser if it is not done rendering the HTML.
Let me assume you are executing a single query, getting the results back and displaying them to a page.
Best option: Page your results. if you Have 4000 records, show the first 50. If you show 200+ records to a user, They cannot digest that much information.
If that does not fit your needs, look at firing one query for 50 results. Make an Ajax call to the the remaining records and build the UI from there, in (reasonably sized) chunks.

Related

How to improve performance on mobile devices using xamarin forms

We are using xamarin forms with prism. We have simple pages with small amount of data to be displayed on each page and include simple calculations. We are using prism navigation service to navigate between pages. We are experiencing some latency from clicking a button to navigating to next page. Data is fetched inside OnNavigatedTo since navigation parameter changes the data. Can someone shed some light of why is there a latency, it is close 1+ second and sometimes 2 seconds.
Also, it seems like each page is getting rendered twice... Once before OnNaviagatedTo and then data changes. OnProperty or OnCollection changed is fired from within OnNavigatedTo and it seems to cause the rendering again.
Version 6.3.0 introduced the concept of OnNavigatingTo, while OnNavigatedTo has been around for a while. There is a distinct difference between the two. Understanding the order in which things occur should help you create a nicer user experience.
New Page is created
OnNavigatedFrom is called
OnNavigatingTo is called
New Page is pushed onto the Navigation Stack and becomes visible
OnNavigatedTo is called
Applications that have to reach out and fetch data can often experience latency issues because it takes time to reach out to the remote service and get the data we want and then parse that data into a usable object. This particular problem was one in which many developers wanted to cut down the demand on the UI with having to refresh as the bindings were being updated which led to the introduction of OnNavigatingTo.
While neither one will reduce network latency it gives you an ability to make the calling page enter an IsBusy state that may display some sort of loading icon which would then be updated to false when NavigateAsync completes and your new page is displayed already loaded.

How to Remove No Longer Used OData Bindings?

Assume a page that shows a complex data structure (for example, an article with many details). This view will be reused from time to time by rebinding it to different articles.
Now, I noticed that the ODataModel keeps all used article entities in memory (also if they are no longer bound to any control).
This will lead to two issues:
Memory consumption increases over time (if application will not be reloaded).
If the application forces a refresh of the data model, all entities will be loaded (also not used).
The second issue seems to be the bigger problem. It slows down the speed of the application.
I have not found a solution for that problem. If I use refresh(true, true) it seems all data will be reloaded.
Is there an way to clean the model?
Edit
Lets say you have a list of thousands of articles. User can click on one of the articles and will navigate to a detailed screen of that article.
The OData model in client side will cache this. To see it, do something like:
var oModel = this.getModel("modelName");
look with the debugger into oModel.oData.
If the user now navigates back and chooses the next article, this will be cached as well.
If user does this 1000 times, all articles are now in the model.
If you trigger a oModel.refresh(true);, all these data (of 1000 articles) will be reloaded not only the one bound to the view.
Now my application is not about showing article information. It's a more complex structure with subitems. Each time user is visiting this page, more data will be cached (and re-fetched in case of a refresh call on the model).
Edit 2
The function updateBindings(bForceUpdate?) seems to help a little bit.
Anyhow, the data accumulation is still there in the ODataModel class.
That means: Each visited data path will stay in memory since the next reload (F5) of the full page. If someone uses such an application over a day, the data accumulates and a refresh call on the model will read all data again, if still bound to a view or not.
Try deleteCreatedEntry(oContext). Even though this is not the supposed use case for this method it might work to delete an entity from the model without triggering a backend request.
You could also try if updateBindings(bForceUpdate?) only triggers an update on actually bound entities.
1) I do not really understand your problem here. What is it exactly that you do? OData always holds the result of your request plus a queue of changes to that request. If you create lots of entries while your application is running, of course the memory consumption will increase. If you want to revert back to the original request you can use resetChanges(). THis way the used memory should decrease again. But you lose all your changes to the model.
2) Maybe you should look into Odata filtering (http://www.odata.org/getting-started/basic-tutorial/) so that you only load the entities you really want. If you only want a part of the entity loaded then you should maybe redesign your entities to avoid a lot of overhead.
It is hard to speculate what your exact problem is.
Well, if you know exactly what are you doing, you can try something like this:
this.getModel("modelname").aBindings = []
Better solution would be go through the aBindings array and remove redundant bindings.

Better Handling of getting data from server in iPhone

I need to improve my coding.so i am finding something better.
My problem is i need to fetch the data from server from 10 different url.that url have images 100.
for example i need to hit
http://192.168.11.222/images/a
http://192.168.11.222/images/b
http://192.168.11.222/images/c
http://192.168.11.222/images/d
http://192.168.11.222/images/e
http://192.168.11.222/images/f
http://192.168.11.222/images/g
http://192.168.11.222/images/h
http://192.168.11.222/images/i
so a b c d e are folder on server that contain images.
Currently i am doing this through NSURLConnectionWithTag and then parse the response.and get saved.is there any another better way to handle this? i also need to show progress bar which is also difficult in this case.
I would setup an NSOperationQueue ,with a single operation per URL and set it to, say, three concurrent operations. Then use NSURLConnection's non-asynchronous API to do the download.
For your progress bar, it's probably good enough to update the progress after each individual file is finished, and do two of them at a time (or something). Chances are latency will be more than half the "progress" anyway, so unless you start trying to predict your ping times, a progress bar based on the actual bytes transferred will not be accurate enough to bother (unless these are very big images).
You will need to learn how operation queues and GCD work, but once you've got that sorted it really won't be much code at all, and it will be rock solid.
Basically you want to add a "block" of code to the operation queue for each URL to download, and the queue will figure out how to download each one, and then when each individual block of code is finished it executes another block on the main thread (dispatch_sync(dispatch_get_main_queue(), ^{ ... })) to update the progress bar.
If you are going to write network related code in your app, I recommend take a look at AFNetworking, it's a wrap of network API iOS already provided with much less hassle.

issues with UITableView performance

I am pulling data from a web service in order to populate my UITableView rows. It loads perfectly fine, however it takes around 4 seconds in order to load the whole data. Is there a way in that I can increase the time to load? Probably by caching it? Or any tips and tricks on what people usually do to do this?
You can display old data and asynchronously fetch using threads the new data and then reload the UITableView
Caching depends on what you're loading. If you're loading, say, Twitter feeds, you should cache the user avatar pictures because you know you'll be fetching them over and over again. If you're writing something like a retail app, you might show items that are on sale. If the items change every Sunday, then cache them the first time you fetch them and don't fetch them again until Sunday. That sort of thing.
Beyond that, there's not much you can do to make the internet faster. If you have control over the web service, you can make the data sent back as concise and simple as possible. You'd be surprised how many milliseconds you can burn parsing complicated XML.
If it makes sense for your app, you can show old data. For a twitter client, it's better to just save the data you've already fetched, show it immediately, and load the new stuff in the background.
If you can't do any of that, then pretty much all you can do is put up a "Loading..." overlay of some sort so that the app doesn't just look frozen and live with the delay.
You can try to use Three20 TTTableViewController, nice tutorial can be found here:
Three20
Moreover, you can add "Load more results" button, look here

iPhone: how many objects should I bring back from webservice?

I am using a Rails webservice and was wondering how many json objects I should bring back on the first call?
Options:
Bring back 200 webservice but only show 25 in the uitableview w/ Load more feature?
Bring back 25 and on clicking load more fetch another 25 from webservice?
????
Without empirical data it's very hard to say, but I would guess that overall, dealing with smaller datasets and more calls would be a little better for the user. The reason being that users tend to "hurry up and wait". They tap something, and when they tap that something they want it 5 seconds ago (hurry up). Once they see the data, they probably want to actually look at it a bit before they request new data (wait).
This is also an argument for background loading as the user is playing around with things, if you can load that other info invisibly before they ask for it all the better for their snappy UI, but you may be wasting the bandwidth on your server, and their battery. Which brings us back to needing good metrics. Make it work and get it into some people's hands, see how it feels, then go from there with some real UX feedback.
If yaou can bring back 200 objects in a relatively short amount of time, the cellular or wifi radios may be able to go into a low power mode for longer, as the user scrolls, enhancing battery life.
If loading over 25 objects takes a long time, you might not want to keep the radios powered up until you know the user wants to see that data.
I will say, don't bother about bringing the objects back, that won't take much time. If you are grtting 500 objects from webservice, its just an xml file coming, it shouldn't take much time to load and parse. You can easily achieve it in background thread or lazy loading. The problem should come, if you are simultaneously trying to update the UI. Drawing a view will consume most of the cycles. So handle it tactfully.