[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: SV: [ANN] Lua 5.2.0 (beta-rc2) now available
- From: David Given <dg@...>
- Date: Thu, 23 Jun 2011 16:02:25 +0100
Alex Queiroz wrote:
[...]
> ...But I still don't think your problem is caused by the locals,
> because you need that state anyway, in one form or the other. Instead,
> the memory usage is caused by the state functions themselves.
Yeah, but if I use goto, I don't *have* any state functions!
e.g. the earlier example becomes:
local function statemachine()
local i = 1
local j = 2
goto ::state1::
::state1::
i = i + 1
goto ::state2::
::state2::
j = j + 1
return
end
Now, all the state machine's state is stored on the stack. No upvalues!
No memory allocations anywhere! Admittedly, we now have a few wasted
goto instructions, but they're *really* cheap. (And omitting such is an
optimisation that could plausibly be done with Lua's compiler.)
However, I'll come clean: I haven't actually *done* any of this, which
means I haven't been able to measure anything, and you don't know
anything until you've measured it. In particular, I really ought to
measure Daurnimator's suggestion about passing state around as
parameters to the state functions. That means that the state functions
don't need upvalues and so won't generate garbage. It would be extremely
instructive to compare against a goto-based state machine implementation.
--
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│ "I have always wished for my computer to be as easy to use as my
│ telephone; my wish has come true because I can no longer figure out
│ how to use my telephone." --- Bjarne Stroustrup
Attachment:
signature.asc
Description: OpenPGP digital signature
- References:
- [ANN] Lua 5.2.0 (beta-rc2) now available, Luiz Henrique de Figueiredo
- Re: [ANN] Lua 5.2.0 (beta-rc2) now available, dcharno
- Re: [ANN] Lua 5.2.0 (beta-rc2) now available, Josh Simmons
- Re: [ANN] Lua 5.2.0 (beta-rc2) now available, David Manura
- Re: [ANN] Lua 5.2.0 (beta-rc2) now available, Lorenzo Donati
- Re: [ANN] Lua 5.2.0 (beta-rc2) now available, David Kastrup
- Re: [ANN] Lua 5.2.0 (beta-rc2) now available, Lorenzo Donati
- Re: [ANN] Lua 5.2.0 (beta-rc2) now available, Roberto Ierusalimschy
- SV: [ANN] Lua 5.2.0 (beta-rc2) now available, Fredrik Widlund
- Re: SV: [ANN] Lua 5.2.0 (beta-rc2) now available, Philippe Lhoste
- Re: SV: [ANN] Lua 5.2.0 (beta-rc2) now available, Alex Queiroz
- Re: SV: [ANN] Lua 5.2.0 (beta-rc2) now available, David Given
- Re: SV: [ANN] Lua 5.2.0 (beta-rc2) now available, Alex Queiroz
- Re: SV: [ANN] Lua 5.2.0 (beta-rc2) now available, David Given
- Re: SV: [ANN] Lua 5.2.0 (beta-rc2) now available, Alex Queiroz
- Re: SV: [ANN] Lua 5.2.0 (beta-rc2) now available, David Given
- Re: SV: [ANN] Lua 5.2.0 (beta-rc2) now available, Alex Queiroz