Re: Perl Performance Tuning



"o" == occitan <occitan@xxxxxxxxxxxxx> writes:

o> http://makepp.sourceforge.net/1.50/perl_performance.html

o> This should be required reading for all Perl hackers, including those
o> who write the alas sometimes suboptimal documentation.

there are some odd points in that and plenty of stuff you missed. also
the wording is very bizarre in some places.

@_ is not called the stack. it is @_. calling with &foo just leaves @_
as it is and so it can be used by the callee. but as that is a bug
waiting to happen, i wouldn't use it just for speedups.

as for passing around long strings, using the $_[0] to directly access
them is also a bug waiting to happen. just pass them by reference and
all is well. you get a proper named variable and no extra copying of
string in the arg list.

who in their right mind uses lots of bit flags for booleans in perl? in
c it makes sense for packing reasons but with perl that won't save
storage since SV's all take up overhead way beyond a few bits. maybe you
mistakenly tried that and it was slow but i wouldn't have even ventured
down that path to begin with.

choosing for vs map is more than just speed. it has to do with side
effects or generating a result list. and the size of the input list
matters too.

use undef instead of 0 makes no sense. you seem to be boolean flag crazy
if that matters to you. as such i would redesign the code to not need so
many flags. flags are not perlish, especially flags in conditionals and
loops. and i believe a basic sv can store an integer or undef (a flag)
using the same space. only a hash or array could have undef as an
element and same space and only if it is done a certain way. $foo{bar} =
undef will use the same space as 0 as it will allocate an SV for
that. but @foo{@keys} = () will not allocate sv's and will same some
space but that means boolean tests on it must be done with exists().

the amount of time you spend on such optimizations would be
better spent on better design and code. and i am not even talking better
algorithms. you can implement the same algorithm in many different ways
and with many different speed results.

avoiding hashes is a very foolish thing to say. arrays as objects are
not much faster at all. look at the brutal history of pseudohashes in
perl. they were invented to do exactly what you claim is important and
they never proved to be so much faster. they only caused nasty hard to
fix bugs when they were used outside their very tiny design envelope. i
would wager that it is how you used the hashes that cause your
problems. this goes again to a better design and not avoiding hashes.

there are so many other ways to optimize programs. i would first do a
full design and code review and then see what comes out of that. then
you can run profiling on the programs and focus on speeding up only the
largest cpu hogs and not all those little things you seem to mention. i
would prefer to waste some cpu in order to have better and more
maintainable code. if you really need speed, use xs not perl.

if you a want a proper design and/or code review, let me know.

uri

--
Uri Guttman ------ uri@xxxxxxxxxxxxxxx -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
.



Relevant Pages

  • Re: Need Estimate of Programming Effort
    ... JS> I'm looking for a simple estimate of a "level of effort", for a Perl ... and design comments are appreciated. ... i have written crawlers before and the client will ... JS> Optional features that can be added are throttling and threading. ...
    (comp.lang.perl.misc)
  • Re: Check POP3 E-mail
    ... > Note the sassign and the undef; ... default language, and, from what I've seen, extremely common in business ... COBOL, so I don't know if those required explicit initialization or not, ... I am familiar with Perl; however, ...
    (comp.lang.perl.misc)
  • about building release 6.0
    ... Build a threading Perl? ... Checking for optional libraries... ... Let me guess what the preprocessor flags are... ... Checking your choice of C compiler and flags for coherency... ...
    (freebsd-questions)
  • UTF-8 issues connecting to Oracle
    ... A Google search turned up a known problem with perl on ES 3 and the UTF8 character set. ... <- STORE= 1 at Oracle.pm line 61 ... 'select collection_name from clone_collection' undef) thr#504010 ... <- DESTROY= undef ...
    (perl.dbi.users)
  • Re: passing data
    ... >>> running script in the first place. ... > your design first before you start coding with only half-formed ideas. ... Ok Matt I take your point but in this particular instance I must admit that ... Ok I will confess, it's just a means to get used to coding in perl, I have ...
    (comp.lang.perl.misc)