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] Win32: stat() only after a failed open() on a module #14408
Comments
From @bulk88Created by @bulk88See attached patch. Not fully smoked. Slightly related to non existent modules and failed paths in @INC should also be faster before 11:20:03.0096859 PM perl.exe 3712 RegOpenKey after 11:19:25.8889882 PM perl.exe 3316 RegOpenKey Perl Info
|
From @bulk880001-Win32-stat-only-after-a-failed-open-on-a-module.patchFrom 25fb429defd25808bc2ab0d86cb48f187f9d380c Mon Sep 17 00:00:00 2001
From: Daniel Dragan <bulk88@hotmail.com>
Date: Thu, 8 Jan 2015 00:10:13 -0500
Subject: [PATCH] Win32: stat() only after a failed open() on a module
See RT ticket for this patch for details.
---
pod/perldelta.pod | 5 +++++
pp_ctl.c | 27 +++++++++++++++++++++++++--
2 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/pod/perldelta.pod b/pod/perldelta.pod
index 7ee0ec4..5f0456d 100644
--- a/pod/perldelta.pod
+++ b/pod/perldelta.pod
@@ -364,6 +364,11 @@ would uncondtionally have around a dozen warnings from hv_func.h. These
warnings have been silenced. GCC all bitness and Visual C++ for Win32 were
not affected.
+=item *
+
+Between 2 and 6 ms and 7 I/O calls have been saved per attempt to open a perl
+module for each path in C<@INC>.
+
=back
=back
diff --git a/pp_ctl.c b/pp_ctl.c
index f2c9856..d69710c 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -3578,6 +3578,7 @@ S_check_type_and_open(pTHX_ SV *name)
{
Stat_t st;
STRLEN len;
+ PerlIO * retio;
const char *p = SvPV_const(name, len);
int st_rc;
@@ -3592,6 +3593,11 @@ S_check_type_and_open(pTHX_ SV *name)
if (!IS_SAFE_PATHNAME(p, len, "require"))
return NULL;
+ /* on Win32 stat is expensive (it does an open() and close() twice and
+ a couple other IO calls), the open will fail with a dir on its own with
+ errno EACCES, so only do a stat to separate a dir from a real EACCES
+ caused by user perms */
+#ifndef WIN32
/* we use the value of errno later to see how stat() or open() failed.
* We don't want it set if the stat succeeded but we still failed,
* such as if the name exists, but is a directory */
@@ -3602,12 +3608,29 @@ S_check_type_and_open(pTHX_ SV *name)
if (st_rc < 0 || S_ISDIR(st.st_mode) || S_ISBLK(st.st_mode)) {
return NULL;
}
+#endif
#if !defined(PERLIO_IS_STDIO)
- return PerlIO_openn(aTHX_ ":", PERL_SCRIPT_MODE, -1, 0, 0, NULL, 1, &name);
+ retio = PerlIO_openn(aTHX_ ":", PERL_SCRIPT_MODE, -1, 0, 0, NULL, 1, &name);
#else
- return PerlIO_open(p, PERL_SCRIPT_MODE);
+ retio = PerlIO_open(p, PERL_SCRIPT_MODE);
+#endif
+#ifdef WIN32
+ /* EACCES stops the INC search early in pp_require to implement
+ feature RT #113422 */
+ if(!retio && errno == EACCES) { /* exists but probably a directory */
+ int eno;
+ st_rc = PerlLIO_stat(p, &st);
+ if (st_rc >= 0) {
+ if(S_ISDIR(st.st_mode) || S_ISBLK(st.st_mode))
+ eno = 0;
+ else
+ eno = EACCES;
+ errno = eno;
+ }
+ }
#endif
+ return retio;
}
#ifndef PERL_DISABLE_PMC
--
1.8.0.msysgit.0
|
From @bulk88 |
From @bulk88On Wed Jan 07 22:10:20 2015, bulk88 wrote:
Bump, any comments from Unix porters on whether the algorithm change would be beneficial on Unix, not just Win32 as the patch has it? Any comments from Win32 porters who will commit this? -- |
From @tonycozOn Sun Jan 11 02:46:02 2015, bulk88 wrote:
Opening a directory for read is successful on most POSIX systems.
Thanks, applied as d345f48. Tony |
The RT System itself - Status changed from 'new' to 'open' |
@tonycoz - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#123566 (status was 'resolved')
Searchable as RT123566$
The text was updated successfully, but these errors were encountered: