Internal and external iteration, fibers

Nick Sabalausky SeeWebsiteToContactMe at semitwist.com
Mon Jan 21 00:44:08 PST 2013


On Mon, 21 Jan 2013 01:18:48 +0100
"Rob T" <alanb at ucora.com> wrote:

> On Friday, 18 January 2013 at 17:59:36 UTC, Nick Sabalausky wrote:
> > Fibers: Too much performance overhead to be a general solution. 
> > Only
> > good for, as an example, heavily I/O-bound stuff.
> 
> Where does the overhead come from? Is the overhead from using 
> fibers the only problem for implementing coroutines?
> 

Real fibers have their own call stacks, so creating them and switching
contexts between them on every iteration can never be made as fast as a
simple for-loop or event-loop (both of which are computationally
trivial). Stackless "fibers" OTOH can do this easily since they
literally *are* trivial switch-driven event-loops under the hood, but
just written in a cleaner way.

> I ask, because if except for the overhead, fibers are a good 
> general solution, then it makes sense to determine if anything 
> can be done to lessen the overhead before trying to implement yet 
> another solution.
> 

Yea, they *would* be a good general solution, and I'm sure the overhead
can be decreased, but AIUI I don't think it's even theoretically
possible for them to optimized enough to compete with any of the other
approaches as a general-purpose thing.

The other stuff can be optimized down as far as being little more than
an increment per iteration. But AIUI, using a real fiber would require
two context-switches per iteration, so I'm not sure that can ever
compete.



More information about the Digitalmars-d mailing list