Front page | perl.perl5.porters |
Postings from August 2012
[perl #114536] Optimize assigning to scalars from @_
From:
David Golden
Date:
August 22, 2012 08:03
Subject:
[perl #114536] Optimize assigning to scalars from @_
Message ID:
rt-3.6.HEAD-11172-1345647788-929.114536-75-0@perl.org
# New Ticket Created by David Golden
# Please include the string: [perl #114536]
# in the subject line of all future correspondence about this issue.
# <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=114536 >
This is a bug report for perl from dagolden@cpan.org,
generated with the help of perlbug 1.39 running under perl 5.16.0.
-----------------------------------------------------------------
[Please describe your issue here]
This ticket suggests a possible peephole optimization, should someone
be interested in pursing it. It is based on a discussion I had with
Nicholas Clark and I agreed to write it up so the idea wouldn't be
lost.
In short, a huge number of pure Perl subroutines start off like this:
sub foo {
my ($one, $two) = @_;
...
}
This assignment requires multiple OPs to execute:
$ perl -MO=Concise,foo,-exec -e 'sub foo {my ($one, $two) = @_; dump }'
main::foo:
1 <;> nextstate(main 1 -e:1) v
2 <0> pushmark s
3 <#> gv[*_] s
4 <1> rv2av[t4] lK/1
5 <0> pushmark sRM*/128
6 <0> padsv[$one:1,2] lRM*/LVINTRO
7 <0> padsv[$two:1,2] lRM*/LVINTRO
8 <2> aassign[t5] vKS
9 <;> nextstate(main 2 -e:1) v:{
a <0> dump s*
b <1> leavesub[1 ref] K/REFC,1
If this is predictable and detectable at the start of a subroutine --
albeit with a variable number of padsv's being assigned -- then it
should be possible for the peephole optimizier to replace them with a
new, single OP that copies an arbitrary number of SV's directly from the
stack to the pad. Depending on the overhead of such a peephole check on
every sub, this could potentially speed up code with many small
subroutines such as occurs in highly-factored code.
(I don't know if similar optimization could be made to work -- or would
be worthwhile -- for shift or array/hash assignment.)
-- David
[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
category=core
severity=wishlist
---
Site configuration information for perl 5.16.0:
Configured by david at Fri Jul 20 11:04:40 PDT 2012.
Summary of my perl5 (revision 5 version 16 subversion 0) configuration:
Platform:
osname=linux, osvers=3.0.0-22-generic, archname=x86_64-linux
uname='linux icarus 3.0.0-22-generic #36-ubuntu smp tue jun 12 17:37:42
utc 2012 x86_64 x86_64 x86_64 gnulinux '
config_args='-de -Dprefix=/home/david/perl5/perlbrew/perls/perl-5.16.0'
hint=recommended, useposix=true, d_sigaction=define
useithreads=undef, usemultiplicity=undef
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
use64bitint=define, use64bitall=define, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='cc', ccflags ='-fno-strict-aliasing -pipe -fstack-protector
-I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-O2',
cppflags='-fno-strict-aliasing -pipe -fstack-protector
-I/usr/local/include'
ccversion='', gccversion='4.6.1', gccosandvers=''
intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='cc', ldflags =' -fstack-protector -L/usr/local/lib'
libpth=/usr/local/lib /lib/x86_64-linux-gnu /lib/../lib
/usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib /usr/lib
libs=-lnsl -ldl -lm -lcrypt -lutil -lc
perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
libc=, so=so, useshrplib=false, libperl=libperl.a
gnulibc_version='2.13'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib
-fstack-protector'
Locally applied patches:
---
@INC for perl 5.16.0:
/home/david/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/x86_64-linux
/home/david/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0
/home/david/perl5/perlbrew/perls/perl-5.16.0/lib/5.16.0/x86_64-linux
/home/david/perl5/perlbrew/perls/perl-5.16.0/lib/5.16.0
.
---
Environment for perl 5.16.0:
HOME=/home/david
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_COLLATE=C
LC_CTYPE=en_US.UTF-8
LC_MESSAGES=en_US.UTF-8
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=/home/david/perl5/perlbrew/bin:/home/david/perl5/perlbrew/perls/perl-5.16.0/bin:~/bin:~/git/utility-scripts:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/opt/vagrant/bin:.
PERLBREW_BASHRC_VERSION=0.45
PERLBREW_HOME=/home/david/.perlbrew
PERLBREW_MANPATH=/home/david/perl5/perlbrew/perls/perl-5.16.0/man
PERLBREW_PATH=/home/david/perl5/perlbrew/bin:/home/david/perl5/perlbrew/perls/perl-5.16.0/bin
PERLBREW_PERL=perl-5.16.0
PERLBREW_ROOT=/home/david/perl5/perlbrew
PERLBREW_VERSION=0.45
PERL_BADLANG (unset)
PERL_EXTUTILS_AUTOINSTALL=--defaultdeps
SHELL=/bin/bash
-
[perl #114536] Optimize assigning to scalars from @_
by David Golden