develooper Front page | perl.perl5.porters | Postings from May 2019

[perl #134096] fix perf deficit in File::Stat (patch against 5.26.2)

From:
perlbug-followup
Date:
May 12, 2019 07:30
Subject:
[perl #134096] fix perf deficit in File::Stat (patch against 5.26.2)
Message ID:
rt-4.0.24-1818-1557642556-940.134096-75-0@perl.org
# New Ticket Created by   
# Please include the string:  [perl #134096]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=134096 >



This is a bug report for perl from lawalsh@cpan.org,
generated with the help of perlbug 1.40 running under perl 5.26.2.


-----------------------------------------------------------------
[Please describe your issue here]

Had written my own stat module and timed it against File::stat
in core.

> stdstat.pl
     s/iter Core  New
Core   10.6   -- -30%
New    7.43  43%   --

My new version seems about 40% faster than the one in core so it
seems it would be good to fix that...

patch against 5.26.2:

> diff -wu stat.pm stat2.pm
--- stat.pm 2016-02-05 07:26:06.000000000 -0800
+++ stat.pm  2019-05-11 22:49:23.249216609 -0700
@@ -24,6 +24,22 @@
	);
     @EXPORT_OK   = ( @fields, "stat_cando" );
     %EXPORT_TAGS = ( FIELDS => [ @fields, @EXPORT ] );
+   my @field_names = ( qw( dev ino mode nlink uid gid rdev size 
+			  atime mtime ctime blksize blocks ));
+
+   sub _mk_accessors() {
+     my $offset=-1;
+     for (@field_names) {
+	++$offset;
+	my $cmd='# line ' . __LINE__ . ' "' . __FILE__ . "\"\n" .
+	  'sub '.$_.'() { $_[0]->['.$offset.'] }';
+	eval "$cmd";
+	die $@ if $@;
+     }
+   }
+
+   &_mk_accessors;
+
 }
 use vars @fields;
 
@@ -178,17 +194,8 @@
	 }
     };
 
-# Class::Struct forbids use of @ISA
 sub import { goto &Exporter::import }
 
-use Class::Struct qw(struct);
-struct 'File::stat' => [
-     map { $_ => '$' } qw{
-  dev ino mode nlink uid gid rdev size
-  atime mtime ctime blksize blocks
-     }
-];
-
 sub populate (@) {
     return unless @_;
     my $stob = new();
@@ -346,11 +353,7 @@
=====================================================

 =back
 
-=head1 NOTE
-
-While this class is currently implemented using the Class::Struct
-module to build a struct-like class, you shouldn't rely upon this.
-
 =head1 AUTHOR
 
 Tom Christians
+Linda Walsh

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=library
    severity=medium
---
Site configuration information for perl 5.26.2:

Configured by law at Fri Jun  8 06:05:36 PDT 2018.

Summary of my perl5 (revision 5 version 26 subversion 2) configuration:
   
  Platform:
    osname=linux
    osvers=4.13.5-isht-van
    archname=x86_64-linux-thread-multi-ld
    uname='linux ishtar 4.13.5-isht-van #2 smp preempt thu oct 5 15.26.26 pdt 2017 x86_64 gnulinux '
    config_args='-r'
    hint=previous
    useposix=true
    d_sigaction=define
    useithreads=define
    usemultiplicity=define
    use64bitint=define
    use64bitall=define
    uselongdouble=define
    usemymalloc=n
    default_inc_excludes_dot=undef
    bincompat5005=undef
  Compiler:
    cc='gcc'
    ccflags ='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-explicit -I/home/perl/perl-5.26.2/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2'
    optimize='-O2'
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-explicit -I/home/perl/perl-5.26.2/include'
    ccversion=''
    gccversion='7.1.0'
    gccosandvers=''
    intsize=4
    longsize=8
    ptrsize=8
    doublesize=8
    byteorder=12345678
    doublekind=3
    d_longlong=define
    longlongsize=8
    d_longdbl=define
    longdblsize=16
    longdblkind=3
    ivtype='long'
    ivsize=8
    nvtype='long double'
    nvsize=16
    Off_t='off_t'
    lseeksize=8
    alignbytes=16
    prototype=define
  Linker and Libraries:
    ld='gcc'
    ldflags ='-fstack-protector-explicit -I/home/perl/perl-5.26.2/include -L/usr/local/lib'
    libpth=/usr/local/lib //lib /usr/lib64/gcc/x86_64-pc-linux-gnu/7/include-fixed /usr/lib /lib/../lib64 /usr/lib/../lib64 /lib /lib64 /usr/lib64 /usr/local/lib //lib /usr/lib64/gcc/x86_64-pc-linux-gnu/7/include-fixed /usr/lib /usr/local/lib //lib /usr/lib64/gcc/x86_64-pc-linux-gnu/7/include-fixed /usr/lib
    libs=-lpthread -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -lgdbm_compat
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=libc-2.19.so
    so=so
    useshrplib=true
    libperl=libperl-5.26.2.so
    gnulibc_version='2.19'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=so
    d_dlsymun=undef
    ccdlflags='-Wl,-E -Wl,-rpath,/home/perl/perl-5.26.2/usr/lib/5.26.2/x86_64-linux-thread-multi-ld/CORE'
    cccdlflags='-fPIC'
    lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector'


---
@INC for perl 5.26.2:
    /home/law/bin/lib
    /home/perl/perl-5.26.2/usr/lib/site_perl/5.26.2/x86_64-linux-thread-multi-ld
    /home/perl/perl-5.26.2/usr/lib/site_perl/5.26.2
    /home/perl/perl-5.26.2/usr/lib/5.26.2/x86_64-linux-thread-multi-ld
    /home/perl/perl-5.26.2/usr/lib/5.26.2

---
Environment for perl 5.26.2:
    HOME=/home/law
    LANG (unset)
    LANGUAGE (unset)
    LC_COLLATE=C
    LC_CTYPE=en_US.UTF-8
    LC_MESSAGES=C
    LC_MONETARY=C
    LC_NUMERIC=C
    LC_TIME=C
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/perl/perl-5.26.2/usr/bin:/home/perl/perl-5.26.2/usr/bin:.:/sbin:/home/law/bin/lib:/home/law/bin:/usr/local/bin:/usr/bin:/bin:/opt/kde3/bin:/usr/sbin:/etc/local/func_lib:/home/law/lib
    PERL5OPT=-Mutf8 -CSA -I/home/law/bin/lib
    PERL_BADLANG (unset)
    SHELL=/bin/bash




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About