Skip to content
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

fix perf deficit in File::Stat (patch against 5.26.2) #16993

Open
p5pRT opened this issue May 12, 2019 · 1 comment
Open

fix perf deficit in File::Stat (patch against 5.26.2) #16993

p5pRT opened this issue May 12, 2019 · 1 comment

Comments

@p5pRT
Copy link

p5pRT commented May 12, 2019

Migrated from rt.perl.org#134096 (status was 'new')

Searchable as RT134096$

@p5pRT
Copy link
Author

p5pRT commented May 12, 2019

From lawalsh@cpan.org

Created by lawalsh@cpan.org

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

Inline Patch
--- 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

Perl Info

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants