|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2021-10-28 14:51 UTC] cmb@php.net
-Status: Open
+Status: Feedback
-Package: *Directory/Filesystem functions
+Package: SPL related
-Assigned To:
+Assigned To: cmb
[2021-10-28 14:51 UTC] cmb@php.net
[2021-10-28 16:01 UTC] dktapps at pmmp dot io
-Status: Feedback
+Status: Assigned
[2021-10-28 16:01 UTC] dktapps at pmmp dot io
[2021-11-02 12:21 UTC] cmb@php.net
-Status: Assigned
+Status: Wont fix
[2021-11-02 12:21 UTC] cmb@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 09:00:01 2025 UTC |
Description: ------------ When a RecursiveIteratorIterator's depth reaches the limit, it still may call its sub-iterator's getChildren(). This manifests as performance degradation when using the below script on a directory with many thousands of files in it. This can be observed by replacing the iterators with a `FilesystemIterator`, which by default won't recurse anyway. As a result, it's 2 orders of magnitude faster than a RecursiveIteratorIterator with depth 0. With the target folder containing 30k files (NTFS on a PCIe Gen4 SSD): - RecursiveDirectoryIterator + maxDepth(0) takes 3.7 seconds - FilesystemIterator takes 0.03 seconds. This is most observable on Windows due to Windows' abysmal I/O performance. Test script: --------------- Slow script: <?php $iterator = new RecursiveDirectoryIterator(sys_get_temp_dir() . '/phpstan/cache/nette.configurator'); $iterator2 = new RecursiveIteratorIterator($iterator); $iterator2->setMaxDepth(0); $start = hrtime(true); foreach($iterator2 as $item){ } var_dump(number_format(hrtime(true) - $start)); -------- Fast script: <?php $iterator2 = new FilesystemIterator(sys_get_temp_dir() . '/phpstan/cache/nette.configurator'); $start = hrtime(true); foreach($iterator2 as $item){ } var_dump(number_format(hrtime(true) - $start)); Expected result: ---------------- The two scripts should be somewhere in the same order of magnitude of performance. Actual result: -------------- The fast script is more than 100x faster than the slow one.