[Stackless] Video on channels

Johan Carlsson johanc at easypublisher.com
Mon Sep 10 20:52:01 CEST 2007

On 9/10/07, olsongt at verizon.net <olsongt at verizon.net> wrote:
> From: Arnar Birgisson <arnarbi at gmail.com>
> Date: 2007/09/10 Mon AM 07:47:10 CDT
> To: johanc at easypublisher.com
> >> In the yield version presented here won't the stack keep growing for
> >> each function call?
> >
> > Yes, absolutely. On my system the stack blows up if goal is >= 999.
> For me the stack blew up at 1000 for your version of the program.  I
> was able to run the stackless version for 100,000 items using less
> than 15 Megs of memory.  I didn't try any higher numbers, but they
> should run fine.
> To answer Johan's question, the stack won't grow with the stackless
> version because tasklets end up going onto the heap.  [That's why they
> call it stackless ;-) ] Yes, you will consume more memory as you track
> down more primes, but you'd also consume memory with the naive
> implementation where you just keep all existing primes in an array.  I
> suppose if you're really concerned about memory consumption, each
> tasklet does consume more memory than each integer in an array would.

Ok FYI, I run the profiler on my imperative code and Hallgrimur
Gunnarsson stackless version of sieve prime (at 10000 iterations,
Arnars code wouldn't make it):

134731 function calls in 246.349 CPU seconds for my imperative version.
10004 function calls in 141.017 CPU seconds for Hallgrimur version.
(124731 function calls in 250.432 CPU seconds for mine using tuple
instead of list)

Clearly the overhead for bookkeeping is relevant of efficiency.

I have no hard figures but I estimate the memory consumption for the stackless
version to be 6-9 times more then my traditional solution.

I find 10004 function calls for 10000 iterations a bit strange, it's
like the send and receive on channels didn't count as calls?

Johan Carlsson
Colliberty Easy Publisher

More information about the Stackless mailing list