[Israel.pm] Article: Optimizing Perl

Shlomo Yona shlomo at cs.haifa.ac.il
Thu Oct 28 03:38:50 PDT 2004


On Thu, 28 Oct 2004, Yuval Yaari wrote:

>> And the answer is...? (I do remember what MJD answered, I'm
>> curious what yours is).
>
> Obviously interpolation takes more time.

And what about the '.' vs. ','?

>> I don't understand the above examples. What's your point?
>
> He is being cynic.
> The examples on that article are not-so-helpful :)
> Moving from a DB file to a real database (the example that Gabor chose) is a 
> much bigger optimization than moving all your print statements from print 
> "$a" to print $a...

Oh!

>> Great. What are your preferences for such a lecture?
>
> Please talk about handling with huge (way above 200MB) data-structures 
> without getting your machine to swap ... :)

Here's the easy answer: buy more memory (no kidding!).

I was facing a real memory problem trying to compile
finite-state networds from xfst's finite-state calculus,
using my 256mg laptop. The problem was that the networks got
too big in intermediate compilations and the whole thing
crashed with a bang.
As their code is closed, I tried many tricks that will
enable me get smaller intermediate networks, so at the end
everything compiles.
After spending two precious days on this, I realized that
spending more time on this will cost me a lot more than
simply buying more memory.
Believe me, after upgrading to 2gb of ram, these problems
are not so big.

There are some real life cases when optimizing code is
simply too expensive (in terms of time you spend on it), and
the simpler, easier and cheaper way to solve the memory
problem is getting enough RAM to do the job.

Having said that, I'll also address your request. The key
for solving such problems is understanding why and when your
operating system swaps, and then see what you can do (if you
can) in order to fit your data access patterns to ones that
play well with the swapping policies. This is usually a
complicated game to play...


-- 
Shlomo Yona
shlomo at cs.haifa.ac.il
http://cs.haifa.ac.il/~shlomo/



More information about the Perl mailing list