[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: lua newbie question: is OO in lua too slow?
- From: Steve Litt <slitt@...>
- Date: Tue, 22 Mar 2011 01:42:21 -0400
On Monday 21 March 2011 21:22:35 Alexander Gladysh wrote:
> On Tue, Mar 22, 2011 at 04:06, Tim Menzies <tim@menzies.us> wrote:
> > and when folks optimize a slow Lua script, is the *first* thing that
> > they look at is the class system and change that? or...?
>
> Premature optimization.
>
> In my practice I can't remember a case when OO stuff was a bottleneck
> in Lua code — in whole system. You find something to be slow — by
> doing actual profiling! — you optimize it. Sometimes — rarely — you
> may have to optimize out OO — but in one specific place, not
> throughout whole program.
>
> Think about code readability and about getting things done.
> Performance is secondary to that, most of the time.
This was exactly my thought when reading the original post. There are many
kinds of problems in which optimization isn't needed. A word processor, for
instance -- the bottleneck is typing speed. If you can word wrap faster than
120 words per minute, then any further efficiency improvement is meaningless.
Some programs run very quickly. Who cares if a report takes 1/2 second or 2
seconds to run? Or a CRUD database program -- the database access is usually
slower than the slowest programming language on a fully loaded and fully used
database. Or take converting vinyl to .ogg -- 90% of the time is taken playing
the record, and your best way of speeding thing up is converting record B to
.wav while concurrently converting .wav A to .ogg A.
Another class of performance problems is the bad algorithm. I had to fix an
incredibly slow program written by a co-worker who had been under too much
time pressure while writing it. I narrowed it down to a string-shift
algorithm, and realized this guy was shifting a string 10 places by shifting
the whole string 1 place 10 times. You could write his algorithm in hand-
optimized assembler and it would still be pig slow.
And in the classes of problems where the programming language really is the
bottleneck, doesn't that scream "Use C"?
My experience with Perl, Python, Ruby, Lua and Bash scripts is that 95% of the
time you write them and they're fast enough without optimizing, even if your
algorithms were a little sloppy. Today's computers are incredibly fast.
SteveT
Steve Litt
Recession Relief Package
http://www.recession-relief.US
Twitter: http://www.twitter.com/stevelitt