[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Speed tips?
- From: David Given <dg@...>
- Date: Fri, 13 Aug 2004 12:10:53 +0100
I've just rewritten one of my tools in Lua. Previously, it was in C++, and was
a badly-designed mess that was practically unmaintainable. The Lua version is
much cleaner, has a more straightforward design, and takes, unfortunately,
about ten to fifteen times as long.
As a result, I've been going through looking for places where I can optimise
it. So far I've managed to shave off about 40% of the time, but it's still
taking about seven seconds to run. My program is a C++ preprocessor that has
to be run every time I compile a source file, so seven seconds is
unacceptable.
What tricks are there that I can use to speed up Lua?
I know the one about global variables being slow. Just adding a 'local' in
front of one variable took two seconds off the total time. Unfortunately, my
program is divided into multiple source files so that I can't make all my
globals into local variables; require() and dofile() both seem to execute
their code in a new chunk with no upvalues. Are there any ways of getting all
my code into one chunk without cut-and-paste?
Would recompiling the lua interpreter to use integer arithmetic make an
appreciable difference? My program doesn't use maths very much.
Any other suggestions?
--
+- David Given --McQ-+
| dg@cowlark.com | Uglúk u bagronk sha pushdug Internet-glob búbhosh
| (dg@tao-group.com) | skai.
+- www.cowlark.com --+