I developed an application for the "Windows Phone 8.1", there I am working with a database comprising 4700 items. On the "Windows Store App 8.1/10 (Desktop/Tablet)" app is works fast, but "Windows Phone 8.1" can be seen that the "UI" works slowly and lagging. Here the analysis of the performance profiler.
CPU profiler results When application is starting the method "OnLaunching" I load the data from the sqlite repository to the static property "IEnumerable" in a static class.
await Task.Run(async () =>
{
if (InstanceMessageService.AllHolidays == null)
{
InstanceMessageService.AllHolidays = _repository.GetAll();
InstanceMessageService.AllCountries = await Task.Run(() =>
InstanceMessageService.AllHolidays.GroupBy(holiday => holiday.Country)
.Select(x => x.First().Country)
.Select(s => new Country()
{
Title = s,
FirstLetter = s[0].ToString()
}).ToList()
);
if (!InstanceMessageService.AllHolidays.Any() || !InstanceMessageService.AllCountries.Any())
{
throw new Exception("Cannot load SQLite data");
}
}
});
Here InstanceMessageService
public static class InstanceMessageService
{
public static IEnumerable<Holiday> AllHolidays { get; set; }
public static IEnumerable<Country> AllCountries { get; set; }
...
}
Now 4700 holiday items contains in static properties (in memory) and 171 items of contries too. It's is not good way i think.
This is my ViewModel code for CalendarsPage. CalendarsPage provides holidays data for Today, Tomorrow or concrete date selected from the calendar control.
public class CalendarPageViewModel : INotifyPropertyChanged
public IEnumerable<Holiday> Holidays
{
get { return _holidays; }
set
{
_holidays = value;
OnPropertyChanged("Holidays");
}
}
public ObservableCollection<Holiday> TodayHolidays
{
get { return _todayHolidays; }
set
{
_todayHolidays = value;
OnPropertyChanged("TodayHolidays");
}
}
public ObservableCollection<Holiday> TomorrowHolidays
{
get { return _tomorrowHolidays; }
set
{
_tomorrowHolidays = value;
OnPropertyChanged("TomorrowHolidays");
}
}
public ObservableCollection<Holiday> SelectedDateHoliday
{
get { return _selectedDateHoliday; }
set
{
_selectedDateHoliday = value;
OnPropertyChanged("SelectedDateHoliday");
}
}
public CalendarPageViewModel()
{
Task task = InitCollections();
InitCommands();
}
**// Slowly magic here**
private async Task InitCollections()
{
Holidays = InstanceMessageService.AllHolidays;
TomorrowHolidays = new ObservableCollection<Holiday>(await Task.Run(() => Holidays.Where(holiday => holiday.Date == DateTime.Now.AddDays(1).Date.ToString("MMM d")).Select(holiday => holiday)));
TodayHolidays = new ObservableCollection<Holiday>(await Task.Run(() => Holidays.Where(holiday => holiday.Date == DateTime.Now.Date.ToString("MMM d")).Select(holiday => holiday)));
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
How can I increase the speed of the application? How to reduce the amount of RAM used? If 4700 elements makes the application slowly and UI works slowly, then 67,000 items will not have enough RAM i think. Sorry for my english.
Aucun commentaire:
Enregistrer un commentaire