Skip to content
Permalink
Browse files
[POSIX] Use access() instead of stat() in FileSystem::fileExists()
https://bugs.webkit.org/show_bug.cgi?id=185882

Reviewed by Geoffrey Garen.

Use access() instead of stat() in FileSystem::fileExists(). stat() returns a lot of information we
do not leverage and local benchmarking on macOS shows access() being > 80% faster than stat():
stat: 0.31567 (lower is better)
access: 0.16074 (lower is better)
stat: 0.303665 (lower is better)
access: 0.165468 (lower is better)

* platform/posix/FileSystemPOSIX.cpp:
(WebCore::FileSystem::fileExists):


Canonical link: https://commits.webkit.org/201337@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@232088 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
cdumez committed May 22, 2018
1 parent 55209fa commit 69aa59bac017a773d5b0148f47b7672d31d46893
Showing with 18 additions and 4 deletions.
  1. +17 −0 Source/WebCore/ChangeLog
  2. +1 −4 Source/WebCore/platform/posix/FileSystemPOSIX.cpp
@@ -1,3 +1,20 @@
2018-05-22 Chris Dumez <cdumez@apple.com>

[POSIX] Use access() instead of stat() in FileSystem::fileExists()
https://bugs.webkit.org/show_bug.cgi?id=185882

Reviewed by Geoffrey Garen.

Use access() instead of stat() in FileSystem::fileExists(). stat() returns a lot of information we
do not leverage and local benchmarking on macOS shows access() being > 80% faster than stat():
stat: 0.31567 (lower is better)
access: 0.16074 (lower is better)
stat: 0.303665 (lower is better)
access: 0.165468 (lower is better)

* platform/posix/FileSystemPOSIX.cpp:
(WebCore::FileSystem::fileExists):

2018-05-22 Brent Fulgham <bfulgham@apple.com>

Avoid keeping FormState alive longer than necessary
@@ -58,10 +58,7 @@ bool fileExists(const String& path)
if (!fsRep.data() || fsRep.data()[0] == '\0')
return false;

struct stat fileInfo;

// stat(...) returns 0 on successful stat'ing of the file, and non-zero in any case where the file doesn't exist or cannot be accessed
return !stat(fsRep.data(), &fileInfo);
return access(fsRep.data(), F_OK) != -1;
}

bool deleteFile(const String& path)

0 comments on commit 69aa59b

Please sign in to comment.