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

Picking a lot of files with FilePicker is extremely slow on Windows, and can raise access exceptions on iOS #19868

Closed
whodges opened this issue Jan 12, 2024 · 5 comments · Fixed by #23047
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info fixed-in-8.0.70 fixed-in-9.0.0-preview.7.24407.4 platform/iOS 🍎 platform/windows 🪟 t/bug Something isn't working t/perf The issue affects performance (runtime speed, memory usage, startup time, etc.)
Milestone

Comments

@whodges
Copy link

whodges commented Jan 12, 2024

Description

Ok, first off: I understand this isn't a common use case, but, in my opinion, it should still work. That said, if I use FilePicker.PickMultipleAsync to select a plethora of files in a folder (say, 200 - and they can be super tiny text files), I experience the following behavior:

Windows: after you click OK, you'll be waiting a very long time for the file results to get returned. Like, close to a minute (even in Release).

iOS: if you try and open one of the returned files, you can get an UnauthorizedAccessException. I typically find this happens with about 200 files, though sometimes it's more. In my testing it can be as low as 180. Sometimes 250+. But it will happen if you select enough. If you only select a few, then it works fine. And sidebar: sometimes I swear I tap 'Open' on iOS with files selected, but then it says no files were picked. If I try again it works.

I made a repo here that can be used to reproduce the problem: https://github.com/whodges/mauifilepicker.git. I also included a CreateTestTextFiles utility method that will make 1000 tiny text files in a specified folder that you can subsequently select via the FilePicker when the app is run. I created them on Windows, then moved them to my MacBook and subsequently to my iPhone (which is an iPhone 14 Pro, btw).

Steps to Reproduce

  1. Get and run the MauiFilePicker app from my repo. Notice in MainPage.OnOpenClickedAsync I have call to CreateTestTextFiles that's commented out; uncomment it for your first run (updating TestTextFileFolder to whatever you want it to be) to make a bunch of tiny files to select via FilePicker.
  2. When the app's run, clicked its 'Open Files...' button, and select all or a subset of said text files (pick at least 250).
  3. At this point, the app will get the results and then try and open and close each file. If you only picked a few files, everything is fine. If you pick a lot, Windows will take a very long time to return the selection results (this is prior to opening and closing each file), while iOS will likely choke with an UnauthorizedAccessException.

Link to public reproduction project repository

https://github.com/whodges/mauifilepicker.git

Version with bug

8.0.5

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS, Windows

Affected platform versions

iOS 17.1.2, Windows 10.0.1.19045

Did you find any workaround?

Nope.

Relevant log output

No response

@whodges whodges added the t/bug Something isn't working label Jan 12, 2024
@whodges
Copy link
Author

whodges commented Jan 12, 2024

Android's super slow too like Windows; I'm using a Galaxy S8+ tablet. I wonder if the selected files get copied to some app sandbox area or something prior to the results being returned and that's what's taking time.

@jsuarezruiz jsuarezruiz added area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info legacy-area-perf Startup / Runtime performance platform/windows 🪟 platform/iOS 🍎 labels Jan 15, 2024
@jsuarezruiz jsuarezruiz modified the milestones: Triaged, Backlog Jan 15, 2024
@ghost
Copy link

ghost commented Jan 15, 2024

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

@mjsb212
Copy link

mjsb212 commented Mar 29, 2024

Related to: #18199 -- also this same problem is on Android...and of course this is backlogged like everything else. I'm thinking we have to 'roll our own' because this will never be fixed soon like ever other issue is never addressed. If any one knows a custom solution or workaround please share.

@Eilon Eilon added t/perf The issue affects performance (runtime speed, memory usage, startup time, etc.) and removed legacy-area-perf Startup / Runtime performance labels May 10, 2024
@MartyIX
Copy link
Contributor

MartyIX commented Jun 13, 2024

This is the reason why it is slow on Windows:

image

I tested using: https://github.com/MartyIX/maui/tree/feature/2024-06-13-PickMultipleFilesAsync-TEST (MartyIX@5be3bf2). It's very similar to https://github.com/whodges/mauifilepicker.git but mine is based on the most recent main (just to be sure).

So there are two observations:

  • If a MAUI app on Windows is packaged, then it's really slow (on my machine it takes 20+ seconds for 200 files being picked)
  • If a MAUI app on Windows is NOT packaged, then it takes about 100 ms (I find it to be instantenous).

Unfortunately, I don't really know how to make it faster. The issue is that StorageItemAccessList.Add(file) (doc) is slow and that's not an issue caused by MAUI but by WinUI 3 (https://github.com/microsoft/WindowsAppSDK or https://github.com/microsoft/microsoft-ui-xaml).

Hope somebody will find this helpful.

@MartyIX
Copy link
Contributor

MartyIX commented Jun 13, 2024

I created #23047. Hopefully, it's the right way to fix this issue.

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 fixed-in-8.0.70 fixed-in-9.0.0-preview.7.24407.4 platform/iOS 🍎 platform/windows 🪟 t/bug Something isn't working t/perf The issue affects performance (runtime speed, memory usage, startup time, etc.)
Projects
None yet
6 participants