[Israel.pm] Article: Optimizing Perl
shlomo at cs.haifa.ac.il
Thu Oct 28 04:47:59 PDT 2004
On Thu, 28 Oct 2004, Yuval Yaari wrote:
>> And what about the '.' vs. ','?
> I can't think of a good reason for a difference between the two,
> I'd be more than glad to hear if such exists, and especially why...
If I recall correctly, it is said in
Effective Perl Programming:
Writing Better Programs With Perl
by Joseph N. Hall, Randal Schwartz
that the ',' operator yields faster execution. I don't
I'll need to see the book again to make sure.
Anyway -- as Gabor said, if you end up needing this kind of
optimization -- you're doing something wrong.
>> Here's the easy answer: buy more memory (no kidding!).
> As if I haven't thought of it myself. :)
> How do you store data-structures that are bigger than your RAM (yes, even
> after I bought more of it)?
> Sometimes you can't buy enough RAM for tasks (10GB data-structures...).
> I think the bioperl guys handle such data-structures, don't they? So there
> should be a good solution...
Ah! The general answer is: you cannot!
Careful inspection of the case at hand might offer clues to
a way to solve the problem. But this depends on the data,
and/or the application.
>> 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.
> What if the data-structure is bigger than the amount of RAM you could buy in
> a reasonable price, like 100GB data-structures? :)
I didn't say this is the silver bullet for your problem. I
simply suggested that in many cases buying more RAM is
smarter and cheaper than banging your head against the wall
trying to solve something you cannot solve or cannot solve
in reasonable time/money.
Let's see your examples to a 100GB data structure and see if
the circumstances allow some trick to allow better usage of
the memory that dramatically reduces swaps.
> I guess that's way beyond the scope of your lecture.
> You might want to mention weakening circular-references in order to make perl
> (>=5.6) garbage collect them, I heard some people have had problems with
I'll tell you a secret: on some platforms, the Perl garbage
collector does not take out the trash.... so in fact you
don't have garbage collection at all!
> BTW: how do I check the actual memory size that my data-structure takes?
I don't know. I think that with one of the lower level modules
you should get the tools to calculate that or even find a
ready made function that can tell you this.
shlomo at cs.haifa.ac.il
More information about the Perl