How to improve Peformance while Loading Mobile Form

  • Thread starter Thread starter Ashok Tho
  • Start date Start date
A

Ashok Tho

Hi All,

To Populate a ListBox on Pocket PC Mobile Form i am using
a ArrayList which is coming inturn from ObjectCollection.
My question is Is there any better way to receive data,
because i am loading around 1500 records.


Mobile Form Code:-
Note:- Where empList is a return values from
RetrieveEmployeesByCustomer

foreach (Employee emp in empList)
{
.......
}


The below one is the sample code of collection class:-

public ArrayList RetrieveEmployeesByCustomer(string key)
{
return Filter(new GenericFilter
(Filters.FilterByPartialKey.Filter), key,
new Comparers.EmployeesByCustomerNumber());
}


public ArrayList Filter(GenericFilter filterFunc, string
filterParam, IComparer sortFunc)

{
ArrayList gefilteList = new ArrayList();
foreach(Employee emp in List)
{
if(filterFunc(emp, filterParam) == true)
{
gefilteList.Add(emp);
}
}

gefilteList.Sort(sortFunc);
return gefilteList;
}

I need better performance than this. Any idea
 
Hello,

Looking to improve performance of code provided below. It looks like you
must have loaded "List" with all employees and are storing them all in
memory. Then when you want to sort a certain way or get those employees
that meet some criteria you filter from that "List".

This looks like an elegant approach to getting data and saving round trips
to the database, however, with the disadvantage of taking up precious
memory. There are two things coming to mind
1) You need to think about how often the data used? If all of it is being
used continuously you may save time by keeping it in memory. There will be
an initial hit for loading it all, but subsequent calls could be faster. I
say could be faster because you have to work within the constraints of a
memory limited device, if you load the memory up, everything will be slow.
If only a small portion of the data is being used or if the data is accessed
infrequently you will probably be better off querying the exact data that
you want. Forinstance, when loading a dropdown you only need an id and a
display value and this data may only need to be queried once so you can use
a datareader vs a dataset. Since you are using custom business objects
instead of a dataset you may take another approach than that datareader. I
use a class I call ListItem which contains properties Id and Text. Then in
my DataLayer I call methods labeled with List ie
ListEmployeesByCustomer(string key). In these methods I just fill a
collection of ListItems. This saves from brining back fully loaded business
obects. Another approach you could leverage is using a LazyLoad pattern on
your Business Objects.

2) You should also keep in mind that the device is small and displaying 100
items in a listbox is going to be a lot for a user to manage so 1500 is well
you get the idea. Try to provide the user with only the data they need.
Forinstance, you may have the user pick the type of customer from a short
list of types, then the customer from a list all customers of just that
type, then the employee.

Obviously these decision are based specifically to each application. Here
is a link to a good article on performance that may help you with your
decisions.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/netcfperf.asp

If you have more questions please ask and I will do my best to answer. I am
interested to hear what you come up with please drop me a note at
http://weblogs.asp.net/tom_krueger/contact.aspx

Take care,

Tom

--
Tom Krueger
Microsoft Corporation
Program Manager
http://weblogs.asp.net/tom_krueger

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
 
Back
Top