Re: Audio synthesis with LuaJIT, and performance

  • From: Mike Pall <mike-1206@xxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Wed, 6 Jun 2012 12:51:25 +0200

Henk Boom wrote:
> Is it a good general rule that all data structures used in inner loops
> should be native structs/arrays, rather than tables?

Not necessarily. It pays off most in loops with high iteration
counts, when the initial type check overhead (which is bigger than
for tables) can be amortized.

> > Also, the Lua
> > version dispatches on the operator, but the C version has the
> > operator hardcoded -- not the same thing.
> 
> Here do you mean that the operator:process_sample() method has to be
> looked up, rather than just using a local operator_process_sample()
> function? Switching that to a local function does seem to save ~2%
> time.

The JIT compiler assumes a monomorphic dispatch, anyway (but a
static C compiler couldn't easily do the same). So it boils down
to verifying that the target is always the same function. That's
not too costly.

I just wanted to point out that it's not an apples-to-apples
comparison. But that's true for most cross-language comparisons.

--Mike

Other related posts: