New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PATCH] add shortcut around syscalls when file not found in win32_stat #15169
Comments
From @bulk88Created by @bulk88See attached patch. before C:\p523\src>timeit -f t.dat perl -e" -e 'nofile' for 0..100000" Version Number: Windows NT 6.1 (Build 7601) C:\p523\src> after C:\p523\src>timeit -f t.dat perl -e" -e 'nofile' for 0..100000" Version Number: Windows NT 6.1 (Build 7601) Perl Info
|
From @bulk880001-add-shortcut-around-syscalls-when-file-not-found-in-.patchFrom 216a69b1f9c8f0133f186b8a7c04d1d24ee8df15 Mon Sep 17 00:00:00 2001
From: Daniel Dragan <bulk88@hotmail.com>
Date: Wed, 10 Feb 2016 15:47:44 -0500
Subject: [PATCH] add shortcut around syscalls when file not found in
win32_stat
win32_stat on success makes ~7 system calls, some from perl, some from CRT,
but on failure, typically file not found, the perl syscalls fails, then the
CRT stat runs, and fails too, so 5 mostly failing system calls are done
for file not found. If the perl syscall says file not found, the
file wont magically come into existence in the next 10-1000 us for the
CRT's syscalls, so skip calling the CRT and the additional syscalls
if the perl didn't find the file. This patch reduces the number of syscalls
from 5 to 1 for file not found for a win32 perl stat. Benchmark and
profiling info is attached to RT ticket for this patch. Note CreateFile on
a dir fails with ERROR_ACCESS_DENIED so in some cases, a failed CreateFile
is still a successful CRT stat() which does things differently so dirs can
be opened.
---
pod/perldelta.pod | 5 +++++
win32/win32.c | 8 ++++++++
2 files changed, 13 insertions(+)
diff --git a/pod/perldelta.pod b/pod/perldelta.pod
index 0a7d4b0..d95df70 100644
--- a/pod/perldelta.pod
+++ b/pod/perldelta.pod
@@ -102,6 +102,11 @@ This empty function call now takes about a third less time to execute:
sub f{} f();
+=item *
+
+On Win32, C<stat>ing or C<-X>ing a path, if the file or directory does not exist
+is now 3.5x faster on a SSD (or any drive) than before.
+
=back
=head1 Modules and Pragmata
diff --git a/win32/win32.c b/win32/win32.c
index b410f66..651b97b 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -1514,6 +1514,14 @@ win32_stat(const char *path, Stat_t *sbuf)
nlink = bhi.nNumberOfLinks;
CloseHandle(handle);
}
+ else {
+ DWORD err = GetLastError();
+ /* very common case, skip CRT stat and its also failing syscalls */
+ if(err == ERROR_FILE_NOT_FOUND) {
+ errno = ENOENT;
+ return -1;
+ }
+ }
}
/* path will be mapped correctly above */
--
1.9.5.msysgit.1
|
From @bulk88"Time of Day","Process Name","PID","Path","Operation","Result","Detail" |
From @bulk88"Time of Day","Process Name","PID","Path","Operation","Result","Detail" |
The RT System itself - Status changed from 'new' to 'open' |
@tonycoz - Status changed from 'open' to 'pending release' |
From @khwilliamsonThank you for submitting this report. You have helped make Perl better. Perl 5.24.0 may be downloaded via https://metacpan.org/release/RJBS/perl-5.24.0 |
@khwilliamson - Status changed from 'pending release' to 'resolved' |
Migrated from rt.perl.org#127508 (status was 'resolved')
Searchable as RT127508$
The text was updated successfully, but these errors were encountered: