Iterating through Folderitem children

Last week I switched to both MacOS 10.15 and to 2019.R2. Most things just work fine, with one big exception: iterating through a folderitem’s children is exceedingly, and I mean exceedingly slow. This is true for both using the new ChildAt(i) method as well as Christian’s FilesMBS to populate an array with all the files in a folder (using FilesMBS, it took about 5 minutes to load the around 7000 files into the array, with the CPU heating up nicely). What’s working as fast as before is using FileListMBS. Any ideas as to why this is so? My harddrive is an APFS-formated SSD.

FilesMBS is just a convenience function using Child() and fills an array.

FileListMBS is to loop over files and skip folderitem as much as possible.

Yes, it is extremely slow. It doesn’t happen in Xcode so it seems this is a Xojo issue. I would say up to 10 times slower.
On top there is a delay of up 5 seconds before it even starts to iterating.
It happens on both SSD and HDD devices.

A solution is to use FilelistMBS instead which is blistering fast.

This is depressing to read.

Did a quick test to iterate a folder with 5219 files.
Before it even starts the first file it took 12 secs!!
Then the iteration for all files took 4 min and 18 secs.

The same with Xojo 2019r1 took approx. 25 secs.

All on a fast SSD in macbook pro.

It isn’t related to API2 though. The ‘old’ code is about the same. So it’s 2019r2 that’s doing something else (wrong).

I see that with r2 there is a new function “Children”. Have you tried this?

Var DesktopFiles as folderitem = SpecialFolder.Desktop for each file as folderitem in DesktopFiles.Children Listbox1.AddRow(file.name) Next

Edit: Make sure you actually call for each file as folderitem in DesktopFiles.Children( false ) or it will resolve the symbolic links/shortcuts/aliases for you.

Instead of using a For loop with indexes, have you tried using a For Each loop?

For Each file As Folderitem in myFolder // do something with “file” Next

[quote=458197:@Greg O’Lone]Instead of using a For loop with indexes, have you tried using a For Each loop?

For Each file As Folderitem in myFolder // do something with “file” Next[/quote]

Yes, that what I already explained. No difference between API1 and 2
It’s just with 2019r2 incredible slow.

I can basically confirm what Christoph said: there is no difference as to whether you use for each … next or the index-based for … next loop with the API2 folderitem or with the API1 folderitem. All of them are really slow. Also, taking up Sam’s comment: adding (false) does nothing as regards execution speed.

I have several apps that need this. What can I do to help?

Not sure how we can help Xojo Inc to fix this. But I do hope they fix it soon. It holds me from using 2019r2

I was excited to try 2019r2’s new “faster” FolderItem class, but it’s now slower than ever before. 10x slower? Try 80x slower! Xojo2019r2 takes over 4 minutes to iterate over a folder with 10,000 files, compared to 3 seconds on Xojo 2019r.1.1… So happy to see this is already fixed per Feedback 57960 <https://xojo.com/issue/57960> Hoping for a quick r2.1 patch, as I can’t imagine such a fundamental part of the Xojo API being 80 times slower for 3 months.