Skip to content
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

Closed
Awesomer9561 opened this issue Jun 21, 2022 · 8 comments
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info platform/android 🤖 s/needs-info Issue needs more info from the author t/bug Something isn't working t/perf The issue affects performance (runtime speed, memory usage, startup time, etc.) (sub: perf)

Comments

@Awesomer9561
Copy link

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

@Awesomer9561 Awesomer9561 added s/needs-verification Indicates that this issue needs initial verification before further triage will happen t/bug Something isn't working labels Jun 21, 2022
@Eilon Eilon added legacy-area-perf Startup / Runtime performance area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info labels Jun 21, 2022
@PureWeen
Copy link
Member

@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?

@PureWeen PureWeen added s/needs-repro Attach a solution or code which reproduces the issue and removed s/needs-verification Indicates that this issue needs initial verification before further triage will happen labels Jun 22, 2022
@ghost
Copy link

ghost commented Jun 22, 2022

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.

@Awesomer9561
Copy link
Author

@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?

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.

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-repro Attach a solution or code which reproduces the issue labels Jun 22, 2022
@Awesomer9561
Copy link
Author

ContactsPicker.zip

@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, this is the app. You can see all the methods over here.

@SunshineSpring666
Copy link

IEnumerable phoneContacts = await Contacts.Default.GetAllAsync();
this method takes very long time (about 1 min) if phone contains many Contacts.

Tried to wrap it into
await Task.Run(async () =>{IEnumerable phoneContacts = await Contacts.Default.GetAllAsync();} );
but the phoneContacts result contains no element, and the code quits unexpectedly if try to get the phoneContacts.Count().

How to make this time-consuming method works in another thread (background, without blocking UI)?
Thanks.

@mattleibow
Copy link
Member

mattleibow commented Feb 7, 2023

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:

@mattleibow mattleibow added s/needs-info Issue needs more info from the author and removed s/needs-attention Issue has more information and needs another look labels Feb 7, 2023
@ghost
Copy link

ghost commented Feb 7, 2023

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.

@ghost ghost added the s/no-recent-activity Issue has had no recent activity label Feb 13, 2023
@ghost
Copy link

ghost commented Feb 13, 2023

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.

@ghost ghost closed this as completed Feb 16, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Mar 18, 2023
@Eilon Eilon added t/perf The issue affects performance (runtime speed, memory usage, startup time, etc.) (sub: perf) and removed legacy-area-perf Startup / Runtime performance labels May 10, 2024
@dotnet-policy-service dotnet-policy-service bot removed the s/no-recent-activity Issue has had no recent activity label May 10, 2024
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info platform/android 🤖 s/needs-info Issue needs more info from the author t/bug Something isn't working t/perf The issue affects performance (runtime speed, memory usage, startup time, etc.) (sub: perf)
Projects
None yet
Development

No branches or pull requests

5 participants