Skip to content

RecursiveDirectoryIterator::hasChildren is slow #11573

Closed
@mvorisek

Description

@mvorisek

Description

image

I belive the currently php-src impl. checks if any iterated item has children on each RecursiveDirectoryIterator::hasChildren call. This is slow.

I propose to reuse current item file entry file flag (d_type = DT_REG on linux, dwFileAttributes on Windows). If a current item is a file, it cannot have children and it will optimize typical usecase - directory with many regular files.

repro iterator code:

$iter = new RecursiveDirectoryIterator(
    $path,
    \RecursiveDirectoryIterator::SKIP_DOTS | \RecursiveDirectoryIterator::FOLLOW_SYMLINKS
);

Measured on Windows, maybe on linux it is faster.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions