develooper Front page | perl.perl5.porters | Postings from September 2012

Why ugly Perl is a guide for optimizing Perl

Thread Next
David Golden
September 21, 2012 08:18
Why ugly Perl is a guide for optimizing Perl
Message ID:
Since finding good "real world" benchmarks for Perl is hard, I think
it might be worth discussing more generally situations where we write
less elegant and readable code for the sake of performance.

Why do I say this?  Because "faster please" and "prettier please" seem
to be the two main camps that people fall into when feature/syntax
debates pop up lately.  Optimizations that allow ugly code to be
prettier and run just as fast (or faster) should be the sort of thing
that both camps can support.

(The third camp is probably the "backward compatible" camp.  And, no,
those aren't mutually exclusive, but I think everyone has their own
prioritization of "fast", "pretty" and "compatible" and most debates
are people talking past each other simply because they have different

So... what are the things that you do that make code *uglier* or
*harder* to maintain for the sake of speed?

Off the top of my head:

* Duplicating code instead of refactoring to small subs to avoid
function/method call overhead.

* Accessing object attribute directly instead of using accessor calls

* Saving a long dereference chain into a temporary lexical prior to
looping to avoid repeated dereferencing

* Accessing elements of @_ directly instead of copying to lexicals

* Passing references to scalars as subroutine arguments to avoid
copying a large scalar

What else have you done?

Once we have a good list, maybe we can benchmark the impact of *those*
to get a sense for the opportunity and assess proposals that address

David Golden <>
Take back your inbox! →
Twitter/IRC: @xdg

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About