apache / cordova-plugin-file

Apache Cordova File Plugin
https://cordova.apache.org/
Apache License 2.0
740 stars 757 forks source link

Listdir takes so much time if directory has data more then 3k entries. #605

Open adeel399 opened 8 months ago

adeel399 commented 8 months ago

Bug Report

Problem

What is expected to happen?

What does actually happen?

Information

I made a local gallery in my app and everything works but one directory whatsapp images have total 154000 images inside it and listdir takes 1 minutes or more to give me all entries array ..

Command or Code

Environment, Platform, Device

Version information

Checklist

breautek commented 8 months ago

154k files in a single directory? ouff...

I'm not sure if you're working with android or iOS but on android I'm curious how much time is spent at listFiles or if the bottleneck is mostly in the cordova bridge.

I believe the iOS equivilant is here

If the bottleneck is at the native API level on iOS, I'm not sure if there is anything that can be done, as far as I can tell iOS doesn't offer any stream API other than NSDirectoryEnumerator which will do a deep recursive traversal (which isn't what we want)

For Android, there is a DirectoryStream API but it's an API 26+ API so it's not something that can be used yet... as cordova needs to support API 24.

If the bottleneck is at the bridge, then introducing a stream read API might be possible so you don't need to transfer the entire dataset of 154k file entries in one API response, but I personally don't have time to allocate introducing such feature.

adeel399 commented 8 months ago

I am working on android ,i am thinking of any option to limit the number of entries