<div dir="ltr"><div>Hi folks<br><br>I've stumbled across VSIReadDirRecursive being really slow when I give it a ridiculously large ZIP file (containing 5 million files across ~1500 subdirectories)<br><br>I spent a while poking round the source code. It looks like VSIArchiveFilesystemHandler::ReadDirEx() performs repeated linear scans through the flat VSIArchiveContent::entries array during recursive directory traversal. For each directory level, it scans all entries from the beginning, resulting in O(n²) time complexity.<br><br>Performance degrades from ~1.3s for the first 5,000 files to ~6.7s for 5000 files once I get 100K files into a 5-million-file ZIP archive, and keeps getting worse from there. I haven't managed to list the whole 5M-file archive yet...<br><br>A couple of possible solutions:<br><br>1. Add a directory index to VSIArchiveContent (add a map of string directory paths to index in the entries array) so we can jumpstart the ReadDirEx implementation at the right place<br>2. make a VSIDIRArchive class (subclass of VSIDIR) and override OpenDir/NextDirEntry, so that it doens't call ReadDirEx repeatedly but instead just returns entries from the VSIArchiveContent::entries array.<br><br>I'm leaning towards (1) because it would presumably improve random lookups by file path also (not just ReadDirRecursive). Is this something that would be accepted as a PR?<br><br>Thanks<br><br></div><br><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px">Regards,</div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px">Craig</div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px"><br></div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px">Platform Engineer<br></div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px">Koordinates</div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px"><a href="http://koordinates.com/" style="color:rgb(17,85,204)" target="_blank">koordinates.com</a> / <a href="https://twitter.com/koordinates" style="color:rgb(17,85,204)" target="_blank">@koordinates</a></div></div></div></div>