Skip to content

Add FileSystem::traverseDirectory() to avoid redundant lstat() per directory entry#63788

Merged
webkit-commit-queue merged 1 commit into
WebKit:mainfrom
cdumez:313538_wtf_traverseDirectory
Apr 29, 2026
Merged

Add FileSystem::traverseDirectory() to avoid redundant lstat() per directory entry#63788
webkit-commit-queue merged 1 commit into
WebKit:mainfrom
cdumez:313538_wtf_traverseDirectory

Conversation

@cdumez
Copy link
Copy Markdown
Contributor

@cdumez cdumez commented Apr 28, 2026

7f663a4

Add FileSystem::traverseDirectory() to avoid redundant lstat() per directory entry
https://bugs.webkit.org/show_bug.cgi?id=313538

Reviewed by Darin Adler.

FileSystem::listDirectory() uses std::filesystem::directory_iterator internally,
which caches each entry's file type from readdir's d_type field. However, it only
returns filenames, discarding the cached type. Callers that need the entry type
then call FileSystem::fileType() per entry, which does a redundant lstat() syscall
to rediscover what directory_iterator already knew.

Add FileSystem::traverseDirectory() that uses directory_iterator directly and
provides both the filename and file type to the callback, reading the type from
directory_entry::symlink_status() which uses the cached d_type without a syscall.
It also avoids materializing all filenames into an intermediate Vector.

Update the four call sites that were doing listDirectory() + fileType() per entry:
NetworkCacheFileSystem, deleteAllFilesModifiedSince, DirectoryFileListCreator,
and DOMFileSystem::listDirectoryWithMetadata.

* Source/WTF/wtf/FileSystem.cpp:
(WTF::FileSystemImpl::deleteAllFilesModifiedSince):
(WTF::FileSystemImpl::traverseDirectory):
* Source/WTF/wtf/FileSystem.h:
* Source/WTF/wtf/playstation/FileSystemPlayStation.cpp:
(WTF::FileSystemImpl::traverseDirectory):
* Source/WebCore/Modules/entriesapi/DOMFileSystem.cpp:
(WebCore::listDirectoryWithMetadata):
* Source/WebCore/html/DirectoryFileListCreator.cpp:
(WebCore::appendDirectoryFiles):
* Source/WebKit/NetworkProcess/cache/NetworkCacheFileSystem.cpp:
(WebKit::NetworkCache::traverseDirectory):

Canonical link: https://commits.webkit.org/312267@main

466ffb5

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows Apple Internal
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe 🛠 win ⏳ 🛠 ios-apple
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 🧪 win-tests ⏳ 🛠 mac-apple
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe ⏳ 🛠 vision-apple
🧪 ios-wk2-wpt 🧪 api-mac-debug ✅ 🛠 gtk3-libwebrtc
✅ 🛠 🧪 jsc 🧪 api-ios ✅ 🧪 mac-wk1 ✅ 🛠 gtk
✅ 🛠 🧪 jsc-debug-arm64 ✅ 🛠 ios-safer-cpp ✅ 🧪 mac-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 vision 🧪 mac-AS-debug-wk2 ✅ 🧪 api-gtk
✅ 🛠 🧪 merge ✅ 🛠 vision-sim ✅ 🧪 mac-wk2-stress ✅ 🛠 playstation
✅ 🧪 vision-wk2 ✅ 🧪 mac-intel-wk2 ✅ 🛠 jsc-armv7
✅ 🛠 tv ✅ 🛠 mac-safer-cpp ✅ 🧪 jsc-armv7-tests
✅ 🛠 tv-sim
✅ 🛠 watch
✅ 🛠 watch-sim

@cdumez cdumez self-assigned this Apr 28, 2026
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Apr 28, 2026
@cdumez cdumez marked this pull request as ready for review April 29, 2026 01:32
@cdumez cdumez requested a review from rniwa as a code owner April 29, 2026 01:32
@cdumez cdumez removed the merging-blocked Applied to prevent a change from being merged label Apr 29, 2026
@cdumez cdumez force-pushed the 313538_wtf_traverseDirectory branch from 559ef94 to 466ffb5 Compare April 29, 2026 01:32
@cdumez cdumez requested review from bnham, darinadler and szewai April 29, 2026 01:32
@cdumez cdumez added the merge-queue Applied to send a pull request to merge-queue label Apr 29, 2026
…rectory entry

https://bugs.webkit.org/show_bug.cgi?id=313538

Reviewed by Darin Adler.

FileSystem::listDirectory() uses std::filesystem::directory_iterator internally,
which caches each entry's file type from readdir's d_type field. However, it only
returns filenames, discarding the cached type. Callers that need the entry type
then call FileSystem::fileType() per entry, which does a redundant lstat() syscall
to rediscover what directory_iterator already knew.

Add FileSystem::traverseDirectory() that uses directory_iterator directly and
provides both the filename and file type to the callback, reading the type from
directory_entry::symlink_status() which uses the cached d_type without a syscall.
It also avoids materializing all filenames into an intermediate Vector.

Update the four call sites that were doing listDirectory() + fileType() per entry:
NetworkCacheFileSystem, deleteAllFilesModifiedSince, DirectoryFileListCreator,
and DOMFileSystem::listDirectoryWithMetadata.

* Source/WTF/wtf/FileSystem.cpp:
(WTF::FileSystemImpl::deleteAllFilesModifiedSince):
(WTF::FileSystemImpl::traverseDirectory):
* Source/WTF/wtf/FileSystem.h:
* Source/WTF/wtf/playstation/FileSystemPlayStation.cpp:
(WTF::FileSystemImpl::traverseDirectory):
* Source/WebCore/Modules/entriesapi/DOMFileSystem.cpp:
(WebCore::listDirectoryWithMetadata):
* Source/WebCore/html/DirectoryFileListCreator.cpp:
(WebCore::appendDirectoryFiles):
* Source/WebKit/NetworkProcess/cache/NetworkCacheFileSystem.cpp:
(WebKit::NetworkCache::traverseDirectory):

Canonical link: https://commits.webkit.org/312267@main
@webkit-commit-queue webkit-commit-queue force-pushed the 313538_wtf_traverseDirectory branch from 466ffb5 to 7f663a4 Compare April 29, 2026 07:14
@webkit-commit-queue
Copy link
Copy Markdown
Collaborator

Committed 312267@main (7f663a4): https://commits.webkit.org/312267@main

Reviewed commits have been landed. Closing PR #63788 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 7f663a4 into WebKit:main Apr 29, 2026
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants