-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When fetching all contacts in MAUI and iterating through it, it takes a lot of time(>30s for around 1500 contacts) #8189
Comments
@Awesomer9561 can you attach a repro please? It's hard to know what's making it slow without one. Maybe if you ToList() the returned results it'll get better? |
Hi @Awesomer9561. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time. |
I tried converting it into a list but the problem remains the same i.e. it takes the same amount of time to convert it into a list. |
Hi, this is the app. You can see all the methods over here. |
IEnumerable phoneContacts = await Contacts.Default.GetAllAsync(); Tried to wrap it into How to make this time-consuming method works in another thread (background, without blocking UI)? |
I think you would want to actually get a list and not an enumerable: var contacts = await Task.Run(async () => {
// get all contacts (delayed items)
var all = await Contacts.Default.GetAllAsync();
// force evaluation
return all.ToList();
}); This will get a list, however it will just sit for a few seconds until ALL contacts are read. You may want to process this as well as they are read: await Task.Run(async () => {
// get all contacts (delayed items)
var all = await Contacts.Default.GetAllAsync();
// force evaluation
foreach (var contact in all) {
// do something...
Console.WriteLine(contact.DisplayName);
}
}); See some info: |
Hi @Awesomer9561. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time. |
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate. |
Description
I am creating an app where it is fetching all the contacts and showing them in a list/collection view, but the problem is whenever I try to iterate through the fetched contacts it will take me around 30+ secs to complete the iteration. I have tried multiple times with different approaches like fetching and assigning them to another variable and from there performing all the actions, implementing pagination to load a set of data at a time. But the stats for all of them are almost the same(10+ secs to load 100-300 contacts). This only happens when I am using the Contacts API in MAUI/Xamarin Essentials, fetching natively using cursor does not have any issues.
Steps to Reproduce
var items = await Microsoft.Maui.ApplicationModel.Communication.Contacts.Default.GetAllAsync();
var count = items.Count();
//It will take around 100ms/1 contact.
Version with bug
6.0.400 (current)
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android API 30, 31
Did you find any workaround?
I tried fetching contacts natively using cursor in Android. Didn't try for iOS.
Relevant log output
No response
The text was updated successfully, but these errors were encountered: