lua vs. stackless python

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

lua vs. stackless python

Phoenix Sol
Please share your opinion: How does lua 'stack up' against Stackless Python?  (intentionally vague ;-)

It's not my intention to stir up a 'flame war' between two 'language lists', though I imagine that could be entertaining...
Seriously though, if you have anything at all to raise here, please do.

Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: lua vs. stackless python

Rob Kendrick
On Thu, 23 Apr 2009 06:52:02 -0700
Phoenix Sol <[hidden email]> wrote:

> Please share your opinion: How does lua 'stack up' against Stackless
> Python?  (intentionally vague ;-)

One executes Lua, the other executes Python.  (intentionally vague ;-)

B.
Reply | Threaded
Open this post in threaded view
|

Re: lua vs. stackless python

Javier Guerra Giraldez
In reply to this post by Phoenix Sol
On Thu, Apr 23, 2009 at 8:52 AM, Phoenix Sol <[hidden email]> wrote:
> Please share your opinion: How does lua 'stack up' against Stackless
> Python?  (intentionally vague ;-)


why stackless?  python is python, i don't see any significant
difference between those implementations when comparing to Lua




--
Javier
Reply | Threaded
Open this post in threaded view
|

Re: lua vs. stackless python

David Ludwig
Stackless Python is a modified version of Python that supports, among
other things, coroutines.  Normal Python has limited support for
yielding, but only within generator functions.  At least, that's my
understanding of things there.  :-)

- David

On Thu, Apr 23, 2009 at 11:03 AM, Javier Guerra <[hidden email]> wrote:
> why stackless?  python is python, i don't see any significant
> difference between those implementations when comparing to Lua
Reply | Threaded
Open this post in threaded view
|

Re: lua vs. stackless python

Phoenix Sol
Stackless's 'tasklets' weigh only a few kilobytes a piece; what does a lua coroutine weigh?

Stackless, going from my limited understanding here, is not 'actually stackless' at all -- but by manipulating the C stack, allows dynamic switching between (arbitrary?) frames.  I have read that lua is 'literally stackless', and does not use a C stack at all... correct?  Please, scientists and engineers, tell me what this means to me...

Stackless has 'channels' which allow for 'communicating sequential processes', and provide a very useful scheduling paradigm that (seems to) blend nicely with the default 'round robin' behaviour of the stackless scheduler; does lua provide an answer to this? If not, would'nt it be fairly trivial to implement?

Stackless has access to Python's massive standard library, plus a huge 'commonwealth' of contributed code to use besides; where lua does not appear so well endowed yet... this has intimidated me for a while, and kept lua 'on the back-burner', but is it really much of a problem, since apparently it's an easy matter to use all of that nice Python code from lua anyway?
(If I start using 'lunaticpython', with stackless, will I get the best of both worlds? Or just a big headache?)

Regarding speed, vm size, ease of embedding and extending, and simplicity, lua is the clear winner, right?

What about stability? Stackless seems to 'hang tough' as a stand-alone, even a *long-running* process; how does lua compare there?

Really, please share your opinion if you can. And please 'reply to all' so that both lists can see, and hopefully inspire some dialog (I tend to forget to 'reply to all' when I mean to ;-).

Want to insult me or whatever personally? Do that here: [hidden email].
(And spam me as well, thou evil crawlers... I archive every one, just for pleasure! ;-)

Thanks!


On Thu, Apr 23, 2009 at 11:15 AM, David Ludwig <[hidden email]> wrote:
Stackless Python is a modified version of Python that supports, among
other things, coroutines.  Normal Python has limited support for
yielding, but only within generator functions.  At least, that's my
understanding of things there.  :-)

- David

On Thu, Apr 23, 2009 at 11:03 AM, Javier Guerra <[hidden email]> wrote:
> why stackless?  python is python, i don't see any significant
> difference between those implementations when comparing to Lua

Reply | Threaded
Open this post in threaded view
|

Re: [Stackless] lua vs. stackless python

Phoenix Sol
In reply to this post by Phoenix Sol
Thanks, Richard.

Whether someone would choose Lua or Stackless Python for coroutines is
probably a matter of preference for the language itself.  But one
thing Stackless might provide that Lua does not, is the ability to
block C function calls as well as Python function calls given that we
shift C stack sections in and out with tasklets.  Or the ability to
persist and unpersist in a cross platform way, running tasklets.

Cheers,
Richard.

I just noticed that there is 'Coco' for lua, which seems to provide similar C stack manipulation to that used in Stackless:

"""
Coco is a small extension to get True C Coroutine semantics for Lua 5.1.

True C coroutine semantics mean you can yield from a coroutine across a C call boundary and resume back to it.

Coco allows you to use a dedicated C stack for each coroutine. Resuming a coroutine and yielding from a coroutine automatically switches C stacks, too.

In particular you can now:

  • Yield across all metamethods (not advised for __gc).
  • Yield across iterator functions (for x in func do).
  • Yield across callbacks (table.foreach(), dofile(), ...).
  • Yield across protected callbacks (pcall(), xpcall(), ...).
  • Yield from C functions and resume back to them.

Best of all, you don't need to change your Lua or C sources and still get the benefits. It's fully integrated into the Lua core, but tries to minimize the required changes.

"""

So far I do not see a lua answer to Stackless's pickling support. (Live, running 'tasklets' in Stackless can be serialized and then resumed - anywhere that you can run Stackless...)

:)
Reply | Threaded
Open this post in threaded view
|

Re: [Stackless] lua vs. stackless python

steve donovan
On Fri, Apr 24, 2009 at 3:52 PM, Phoenix Sol <[hidden email]> wrote:
> So far I do not see a lua answer to Stackless's pickling support. (Live,
> running 'tasklets' in Stackless can be serialized and then resumed -
> anywhere that you can run Stackless...)

Oh there are a whole bunch of pickles available for Lua (picking one
can be an issue.) I believe LuaLanes solves the problem quite
generally.

As for heavy-duty persistence, Pluto is the way to go.

steve d.
Reply | Threaded
Open this post in threaded view
|

Re: [Stackless] lua vs. stackless python

Phoenix Sol
In reply to this post by Phoenix Sol
Good question; I just picked this up somewhere, and cannot find a definitive answer; do you have it?
And I suppose my wording glosses over the fact that it depends on what you are doing, right?

So is there a known 'memory overhead' for a tasklet?

And is there a known overhead for a lua coro? (Maybe it would be more fair to compare a tasklet to a 'Coco' coroutine... but still I wonder what the overhead of wrapping a function with coroutine.wrap() is...)


On Fri, Apr 24, 2009 at 7:38 AM, Richard Tew <[hidden email]> wrote:
On Thu, Apr 23, 2009 at 3:27 PM, Phoenix Sol <[hidden email]> wrote:
> Stackless's 'tasklets' weigh only a few kilobytes a piece; what does a lua
> coroutine weigh?

How do you know they are only a few kilobytes a piece?

Cheers,
Richard.

Reply | Threaded
Open this post in threaded view
|

Re: [Stackless] lua vs. stackless python

Peter Cawley
A coroutine appears to cost around a kilobyte (20695 - 19601 = 1094 bytes):

collectgarbage"collect"
print(collectgarbage"count" * 1024) --> 19559
local function F()
end
print(collectgarbage"count" * 1024) --> 19601
local C = coroutine.wrap(F)
print(collectgarbage"count" * 1024) --> 20695

Test done on Win32/Vista, self-compiled Lua (using Visual Studio
2008), source code executed all-at-once from a file rather than from
an interactive terminal.

On Fri, Apr 24, 2009 at 4:52 PM, Phoenix Sol <[hidden email]> wrote:
> And is there a known overhead for a lua coro? (Maybe it would be more fair
> to compare a tasklet to a 'Coco' coroutine... but still I wonder what the
> overhead of wrapping a function with coroutine.wrap() is...)
>
Reply | Threaded
Open this post in threaded view
|

Re: [Stackless] lua vs. stackless python

Phoenix Sol
Very nice, thanks Peter!

On Fri, Apr 24, 2009 at 9:08 AM, Peter Cawley <[hidden email]> wrote:
A coroutine appears to cost around a kilobyte (20695 - 19601 = 1094 bytes):

collectgarbage"collect"
print(collectgarbage"count" * 1024) --> 19559
local function F()
end
print(collectgarbage"count" * 1024) --> 19601
local C = coroutine.wrap(F)
print(collectgarbage"count" * 1024) --> 20695

Test done on Win32/Vista, self-compiled Lua (using Visual Studio
2008), source code executed all-at-once from a file rather than from
an interactive terminal.

On Fri, Apr 24, 2009 at 4:52 PM, Phoenix Sol <[hidden email]> wrote:
> And is there a known overhead for a lua coro? (Maybe it would be more fair
> to compare a tasklet to a 'Coco' coroutine... but still I wonder what the
> overhead of wrapping a function with coroutine.wrap() is...)
>

Reply | Threaded
Open this post in threaded view
|

Re: [Stackless] lua vs. stackless python

Phoenix Sol
So I attempted to measure the memory overhead of a Stackless tasklet, with 'Recipe 286222' from ActiveState's Cookbook:
(on Linux 2.6.27-11-generic SMP x86_64)

def empty(): pass
b4 = memory()
print "before:", b4
t = stackless.tasklet(empty)()
after = memory()
print "after:", after
print "difference:", memory(b4)

Which yields:
    difference: 4096.0

And a slightly modified version of Peter's test on my platform:

collectgarbage"collect"
local function F()
end
before = (collectgarbage"count" * 1024)
local C = coroutine.wrap(F)
after = (collectgarbage"count" * 1024)
print(after - before)

Yields:
    1280

But perhaps a more reasonable question is, "how many licks does it take to get to the center of a tootsie roll pop?"


On Fri, Apr 24, 2009 at 9:12 AM, Phoenix Sol <[hidden email]> wrote:
Very nice, thanks Peter!


On Fri, Apr 24, 2009 at 9:08 AM, Peter Cawley <[hidden email]> wrote:
A coroutine appears to cost around a kilobyte (20695 - 19601 = 1094 bytes):

collectgarbage"collect"
print(collectgarbage"count" * 1024) --> 19559
local function F()
end
print(collectgarbage"count" * 1024) --> 19601
local C = coroutine.wrap(F)
print(collectgarbage"count" * 1024) --> 20695

Test done on Win32/Vista, self-compiled Lua (using Visual Studio
2008), source code executed all-at-once from a file rather than from
an interactive terminal.

On Fri, Apr 24, 2009 at 4:52 PM, Phoenix Sol <[hidden email]> wrote:
> And is there a known overhead for a lua coro? (Maybe it would be more fair
> to compare a tasklet to a 'Coco' coroutine... but still I wonder what the
> overhead of wrapping a function with coroutine.wrap() is...)
>



measure_tasklet.py (1K) Download Attachment
measure_coro.lua (228 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [Stackless] lua vs. stackless python

gary ng
In reply to this post by Phoenix Sol

lua coroutine is very lean on memory but with coco patch, it needs much more memory(which I believe is related to using the C-stack instead of heap).


--- On Sat, 4/25/09, Phoenix Sol <[hidden email]> wrote:

> From: Phoenix Sol <[hidden email]>
> Subject: Re: [Stackless] lua vs. stackless python
> To: "Lua list" <[hidden email]>, "[hidden email]" <[hidden email]>
> Date: Saturday, April 25, 2009, 12:12 AM
> Very nice, thanks Peter!
>
> On Fri, Apr 24, 2009 at 9:08 AM,
> Peter Cawley <[hidden email]>
> wrote:
>
> A coroutine appears to cost around a kilobyte (20695 -
> 19601 = 1094 bytes):
>
>
>
> collectgarbage"collect"
>
> print(collectgarbage"count" * 1024) --> 19559
>
> local function F()
>
> end
>
> print(collectgarbage"count" * 1024) --> 19601
>
> local C = coroutine.wrap(F)
>
> print(collectgarbage"count" * 1024) --> 20695
>
>
>
> Test done on Win32/Vista, self-compiled Lua (using Visual
> Studio
>
> 2008), source code executed all-at-once from a file rather
> than from
>
> an interactive terminal.
>
>
>
> On Fri, Apr 24, 2009 at 4:52 PM, Phoenix Sol <[hidden email]>
> wrote:
>
> > And is there a known overhead for a lua coro? (Maybe
> it would be more fair
>
> > to compare a tasklet to a 'Coco' coroutine...
> but still I wonder what the
>
> > overhead of wrapping a function with coroutine.wrap()
> is...)
>
> >
>
>
>
>


     
Reply | Threaded
Open this post in threaded view
|

Re: [Stackless] lua vs. stackless python

curt
This post has NOT been accepted by the mailing list yet.
Speaking of this, I just implemented http://northarc.com/tuna which does for lua what stackless does for Python. At least that was the idea :)